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 keys [] = length keys
loop keys ((l,r):lrs) = loop keys1 lrs
  where
    keys1 = takeWhile (r >) $ dropWhile (l >) keys
-- maybe TLE