'use strict'
const Main = (input) => {
  let tmp = input.split('\n');
  let CardN = tmp[0].split(' ').map(Number)[0];
  let GateN = tmp[0].split(' ').map(Number)[1];
  let NumTop = 1;
  let NumBtm = CardN;
  // console.log({ CardN, GateN });

  for (let i = 1; i <= GateN; i++) {
    let top = tmp[i].split(' ').map(Number)[0];
    let btm = tmp[i].split(' ').map(Number)[1];
    // console.log({ top, btm });
    NumTop = NumTop <= top ? top : NumTop;
    NumBtm = NumBtm >= btm ? btm : NumBtm;
    // console.log({ NumTop, NumBtm });
  }
  console.log(NumBtm - (NumTop - 1));
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
