import Data.List
import Control.Monad
prep::[(Int,Int)]->[(Int,Int)]
prep = sortBy (\ (a1,b1) -> \ (a2,b2) -> if a1==a2 then compare b2 b1 else compare a1 a2 )

solver::Int->(Int,Int)->[(Int,Int)]->Int
solver i _ [] = i
solver i (l,r) ((a,b):rest) = if (l>=b)||(r<=a) then solver (i+1) (a,b) rest else solver i (max a l,min b r) rest

main::IO()
main=do
  nm<-getLine
  let n:m:[] =map read (words nm) ::[Int]
  sss <- forM [1..m] (\_ -> getLine)
  let d = map (\x ->let a:b:[]= map read (words x)in (a,b)) sss
  let dat = prep d
  print (solver  1 (head dat) (tail dat))
