import Control.Monad

chooseMinSnd :: Int -> [(Int, Int)] -> Int 
chooseMinSnd currentMin [] = currentMin
chooseMinSnd currentMin (x:xs) 
  | (snd x) < currentMin = chooseMinSnd (snd x) xs
  | otherwise = chooseMinSnd currentMin xs

tuplify :: [[Int]] -> [(Int, Int)]
tuplify [] = []
tuplify (x:xs) = (x !! 0, x !! 1) : (tuplify xs)

filterBridges :: [(Int, Int)] -> Int -> [(Int, Int)]
filterBridges tups threshold = filter (\x -> not ((fst x) < threshold) && ((snd x) >= threshold)) tups

dropBridges :: [(Int, Int)] -> Int -> Int -> Int 
dropBridges [] _ counter = counter 
dropBridges [x] _ counter = counter + 1
dropBridges tups currentMin counter = dropBridges (filterBridges tups (chooseMinSnd currentMin tups)) (length tups) (counter + 1)

main = do
  [n, m] <- map (\x -> read x :: Int) . words <$> getLine 
  _wars <- replicateM m (map (\x -> read x :: Int) . words <$> getLine) 
  let wars = tuplify _wars
  print $ dropBridges wars (maxBound :: Int) 0
