import Control.Monad

main = do
  [n, m] <- map read . words <$> getLine
  xs <- replicateM m (map read . words <$> getLine)
  let x = concat xs
  print $ func x 1 n

func :: [Int] -> Int -> Int -> Int
func [] a b = b - a + 1
func (x:y:xs) a b = func xs na nb
  where
    na =
      if a > x
        then a
        else x
    nb =
      if b < y
        then b
        else y
