import qualified Data.ByteString.Char8 as BS
import Control.Monad
import Data.List
import Data.Maybe
import Data.Char

solve :: [(Int,Int)] -> Int -> Int -> Int
solve [] memo bridges = bridges 
solve ((to,from):xs) memo bridges
  | from <= memo = solve xs memo bridges
  | otherwise = 1 + solve xs (to-1) (bridges+1)

main = do
  [n,m] <- map read . words <$> getLine :: IO [Int]
  xs <- replicateM m $ do 
      s <- BS.getLine
      let (from, s') = fromJust $ BS.readInt s
      let (to, _) = fromJust $ BS.readInt $ BS.dropWhile isSpace s'
      return (to, from)
  
  print $ solve (sort xs) 0 0