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 ass

readInts :: IO [Int]
readInts = map (fst . fromJust . B.readInt) . B.words <$> B.getLine

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