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

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

readInts :: IO [Int]
readInts = map (maybe (error "parse error" fst . B.readInt) . B.words <$> 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
