function Main(input) {
  input = input.split('\n');
  var array = input.shift();
  array = array.split(' ');
  var N = array [0];
  var M = array [1];
  var min = -1;
  var max = -1;
  for(var i = 0; i < M; i++){
  array = input.shift();
  array = array.split(' ');
    if(min == -1) {
      min = parseInt(array[0]);
    } else {
      min = Math.max(array[0], min);
    }
    if(max == -1) {
      max = parseInt(array[1]);
    } else {
      max = Math.min(array[1], max);
    }
  }
  var result = 0;
  for(var i= min;i < max + 1;i++){
    if(min<=i && i<=max){
       result++;
    }
  }
  console.log(result);
  
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
