'use strict'
function main(input) {
  input = input.trim().split('\n')
  input.shift()
  let min = 0
  let max = 1000000
  input.forEach(val => {
    let temp = val.split(' ').map(val => Number(val))
    if (temp[0] > min) min = temp[0]
    if (temp[1] < max) max = temp[1]
  })
  let ans = max - min + 1
  console.log(ans > 0 ? ans : 0)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));
