import Control.Monad
import Data.List

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

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

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