import Control.Monad

main :: IO ()
main = do
  [n, m] <- readInts
  ass <- replicateM m readInts
  print $ solve (replicate n 0) ass

readInts :: IO [Int]
readInts = map read . words <$> getLine

solve :: [Int] -> [[Int]] -> Int
solve xs [] = minimum xs
solve xs ([a, b]:ass) = solve (map (add a b) xs) ass
  where
    add a b x
      | a <= x && x <= b
        = x + 1
      | otherwise
        = x

