function main(input) {
  var inputArray = input.trim().split('\n');
  var cardNum = Number(inputArray[0].split('\s')[0]);
  var LList = [];
  var RList = [];
  inputArray.filter((item, index) => index !== 0).forEach(item => {
    LList.push(Number(item.split('\s')[0]));
    RList.push(Number(item.split('\s')[1]));
  });
  var maxL = Math.max.apply(null, LList);
  var minR = Math.min.apply(null, RList);
  if (maxL > minR) {
    console.log(0);
  } else {
    console.log(minR - maxL + 1);
  }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));