import Control.Monad
import Text.Printf
import Control.Applicative

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

main :: IO()
main = do
  [n, m] <- map read . words <$> getLine
  ab <- replicateM m $ getInts
  putStrLn $ show $ slv (tail ab) ((head ab)!!1) 0

slv :: [[Int]] -> Int -> Int -> Int
slv [] _ ret = ret + 1
slv (a:as) bound ret | a!!0 >= bound = slv as (a!!1) (ret + 1)
                     | otherwise = slv as (min bound (a!!1)) ret 