{-# LANGUAGE BangPatterns #-}

import Control.Monad
import qualified Data.ByteString.Char8 as B
import Data.Char
import Data.List

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

readInts :: IO [Int]
readInts = unfoldr (B.readInt . B.dropWhile isSpace) <$> B.getLine

solve :: Int -> Int -> [[Int]] -> Int
solve !n _ [] = n
solve !n !p ([a, b]:ass)
  | a >= p
    = solve (n + 1) b ass
  | a < p
    = solve n p ass
