"use strict";
function Main(input) {
  const args = input.split('\n');
  const NM = args.shift().split(' ').map(m => parseInt(m));
  const N = NM.shift();
  const M = NM.shift();
  let cL = 0;
  let cR = Math.pow(10, 5);
  for (let arg of args) {
    const LR = arg.split(' ').map(m => parseInt(m));
    const L = LR.shift();
    if (L > cL) {
      cL = L;
    }
    const R = LR.shift();
    if (R < cR) {
      cR = R;
    }
  }
  const ret = cR - cL + 1;
  console.log(ret > 0 ? ret : 0);

}

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