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

