function Main(input){
  var all = input.split("\n");
  all.shift();
  var N =input.split("\n")[0].split(" ")[0];
  N = parseInt(N,10);
  var M =input.split("\n")[0].split(" ")[1];
  M = parseInt(M,10);
  var R = [];
  var L = [];
  var Lm = 0,Rm = 0;
  for(i=0;i<=(M-1);i++){
    R[i] = all[i].split(" ")[1];
    R[i] = parseInt(R[i],10);
    L[i] = all[i].split(" ")[0];
    L[i] = parseInt(L[i],10);
    if(i===0){
      Lm = L[i];
      Rm = R[i];
    }else{
      if(Lm<L[i]){
        Lm = L[i];
      }
      if(Rm>R[i]){
        Rm = R[i];
      }
    }
  }
  if(Lm > Rm){
    console.log("0");
  }else{
    var ans = (Rm - Lm) + 1;
    console.log(ans);
  }
}
  Main(require('fs').readFileSync('/dev/stdin','utf8'));

