'use strict';

function main(stdin) {
  const input = stdin.split('\n');
  const N = input.shift().split(' ').map(v => parseInt(v, 10))[0];
  const gates = input.map(g => g.split(' ').map(v => parseInt(v, 10)));

  const validCards = gates.reduce((prev, next) => {
    if (prev[0] > next[1] || prev[1] < next[0]) return [0, -1];
    return [
      Math.max(prev[0], next[0]),
      Math.min(prev[1], next[1])
    ];
  });

  console.log(validCards[1] - validCards[0] + 1);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));