main = do
  li <- getLine
  let [n,m] = map read $ words li
  lrs <- getLRs (pred m)
  let answer = compute n lrs
  print answer

getLRs 0 = return []
getLRs k = do
  li <- getLine
  let [l,r] = map read $ words li
  lrs <- getLRs (pred k)
  return ((l,r):lrs)

compute n lrs = loop 1 n lrs

loop a b _
  | a > b = 0
loop a b [] = b - a + 1
loop a b ((l,r):lrs) = loop (max a l) (min b r) lrs
