main = do
  li <- getLine
  let [n,m] = map read $ words li
  lrs <- getLRs (pred m)
  let answer = compute 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 lrs = max 0 (r - l + 1)
  where
    l = maximum $ map fst lrs
    r = minimum $ map snd lrs
