{-# LANGUAGE BangPatterns, MagicHash #-}
import Control.Monad
import Control.Applicative
import Data.List
import Data.Maybe
import Data.Bits
import qualified Data.IntMap.Strict as M
import qualified Data.ByteString.Char8 as B
import qualified Data.Vector.Unboxed as V
import Data.Vector.Unboxed ((!))
import Data.Tuple
import Data.Ord (Down(..))
import Data.Coerce
                                 
query :: Int -> [(Int,Int)] -> Int
query n =
  snd
  . V.ifoldl' (\(x,cnt) a b -> let x' = min b x
                               in if x'-1 == a
                                  then (n,cnt+1)
                                  else (x',cnt)) (n,0)
  . V.init . V.accum min (V.replicate n n)
     
main :: IO ()
main = do
  [n,m] <- map read . words <$> getLine
  ls <- map ((\[x,y] -> (x-1,y-1)) . unfoldr (B.readInt . B.dropWhile (== ' ')))
          . B.lines
        <$> B.getContents
  putStrLn $ show $ query n ls
