import Control.Monad

isOverlapped :: (Int,Int) -> (Int,Int) -> Bool
isOverlapped (from1, to1) (from2, to2) = not isNotOverlapped
  where isNotOverlapped = (to2 < from1) || (to1 < from2)

toOverlapped :: (Int,Int) -> (Int,Int) -> (Int, Int)
toOverlapped (from1, to1) (from2, to2) = (max from1 from2, min to1 to2)

require :: [(Int, Int)] -> [[Int]] -> [(Int, Int)]
require already []           = already
require []      ([r1,r2]:xs) = require [(r1, r2)] xs
require already ([r1,r2]:xs)
  | anyOverlapped = require (notOverlapped ++ overlappedList) xs
  | otherwise     = require (already ++ [(r1, r2)]) xs
  where (overlapped, notOverlapped) = span (isOverlapped (r1, r2)) already
        anyOverlapped               = not . null $ overlapped
        overlappedList              = map (toOverlapped (r1, r2)) overlapped

solve :: [[Int]] -> Int
solve requests = length $ require [] requests

main :: IO ()
main = do
  [n, m] <- map read . words <$> getLine
  requests <- replicateM m $ map read . words <$> getLine
  print $ solve requests