import Control.Monad
import Data.List

solve = foldl' f (0, 0)
  where
    f (n, c) [a, b] = if a < n then t n c else t b (1 + c)
    t x y = (,) x $! y

readN = map read . words <$> getLine

main = do
  [n, m] <- readN
  rs <- replicateM m readN
  print . snd . solve . sortOn last $ rs
