import Control.Monad
import Data.List

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

toOverlapped :: [Int] -> [Int] -> [Int]
toOverlapped [from1, to1] [from2, to2] = [max from1 from2, min to1 to2]

toBridges :: [Int] -> [[Int]] -> [[Int]]
toBridges bridge [] = [bridge]
toBridges bridge (r:rs)
  | isOverlapped bridge r = toBridges (toOverlapped bridge r) rs
  | otherwise             = bridge:toBridges r rs

sortRequests :: [[Int]] -> [[Int]]
sortRequests list = sortBy ordering list
  where ordering = (\[from1, to1] [from2, to2] -> compare (from1, to1) (from2, to2))

solve :: [[Int]] -> [[Int]]
solve (r:rx) = toBridges r rx

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