function Main(input) {
  var tmp = input.split("\n");
  tmp.shift();
  var left = 1;
  var right = 10000000;
  
  for(var i = 0; i < tmp.length; i++){
    var tmp2 = tmp[i].split(" ").map((tmp)=>Number(tmp));
    if(tmp2[0] > left){
       left = tmp2[0];
    }
    if(tmp2[1] < right){
       right = tmp2[1];
    }
  }
  
  console.log(Math.max((right - left + 1),0));
}

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