function Main(input) {
    input = input.split("\n")
    input = input.map(elem => {
        return elem.split(' ').map(str => parseInt(str))
    })
    const N = input[0][0]

    const makeInterval = (a, b) => {
        const start = a[0] > b[0] ? a[0] : b[0]
        const end = a[1] > b[1] ? b[1] : a[1]
        return [start, end]
    }

    const resultArr = input.reduce((accum, current, index) => {
        if (index === 0) {
            return accum
        }
        return makeInterval(accum, current)
    }, [1, N])

    const result = (resultArr[0] > resultArr[1]) ? 0 : resultArr[1] - resultArr[0] + 1

    console.log(result)
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"))