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

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

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

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

    console.log(result)



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