process.stdin.resume();
process.stdin.setEncoding('utf8');

var lines = []
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});

reader.on('line', (line) => {
  lines.push(line);
});

reader.on('close', () => {
  var nandm = lines[0].split(' ');
  var n = Number(nandm[0]);
  var m = Number(nandm[1]);

  var start = [];
  var end = [];

  for(i=1; i<=m; i++){
    var tmp = lines[i].split(' '); 
    start.push(Number(tmp[0]));
    end.push(Number(tmp[1]));
  }
  var s = Math.max(...start);
  var e = Math.min(...end);

  var output = (e-s)+1;
  if(output < 0){
    output = 0;
  }
  console.log(output);
  
});