import Control.Monad
import Data.List

solve = count . scanl' f 0
  where
    f n [a, b] = if a < n then n else b
    count = length . nub . tail

readN = map read . words <$> getLine

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