function Main(input) {
  var N = parseInt(input.split("\n")[0].split(" ")[0]);//IDカード
  var M = parseInt(input.split("\n")[0].split(" ")[1]);//ゲート
  var left = 1;
  var right = N;
  
  for(var i = 1; i <= M; i++){
    var tmp = input.split("\n")[i].split(" ").map((tmp)=>Number(tmp));
    var tmpMin = tmp[0];
    var tmpMax = tmp[1];
       left = Math.max(tmpMin,left);
       right = Math.min(tmpMax,right);
    //console.log(right + "," +left);
    if(right < left){
       console.log("0");
      return;
       }
    
  }
  
  console.log(right - left + 1);
}

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