function Main(input) {
  var N = parseInt(input.split("\n")[0].split(" ")[0]);//IDカード
  var M = parseInt(input.split("\n")[0].split(" ")[1]);//ゲート
  var output = 0;
  var frecList = [];
  for(var i = 1; i <= N; i++){
    frecList.push(i);
  }
  
  for(var i = 1; i <= M; i++){
    var tmpMin = parseInt(input.split("\n")[i].split(" ")[0]);
    var tmpMax = parseInt(input.split("\n")[i].split(" ")[1]);
    for(var j = 0; j <= N; j++){
      if(frecList[j] < tmpMin || frecList[j] > tmpMax){
        frecList[j] = 0;
      }
    }
  }
  
  for(var i = 0; i < frecList.length; i++){
    if(frecList[i] != 0){
       output++;
       }
  }
  console.log(output);
}

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