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 tmpMax = tmp[1];
    if(tmp[0] > left){
       left = tmp[0];
    }
    if(tmp[1] < right){
       right = tmp[1];
    }
  }
  
  console.log(Math.max((right - left + 1),0));
}

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