import Control.Monad
import Text.Printf
import Control.Applicative
import Data.List

getInts :: IO (Int, Int)
getInts = do
  a <- map read . words <$> getLine
  return (a!!0, a!!1)

main :: IO()
main = do
  [n, m] <- map read . words <$> getLine
  tmpab <- replicateM m $ getInts
  let ab = sortOn fst tmpab
  let leftslv = slv (tail ab) (snd (head ab)) 0
  let revab = tmpList n ab []
  putStrLn $ show $ min leftslv $ slv (tail revab) (snd (head revab)) 0

slv :: [(Int, Int)] -> Int -> Int -> Int
slv [] _ ret = ret + 1
slv (a:as) bound ret | fst a >= bound = slv as (snd a) (ret + 1)
                     | otherwise = slv as (min bound (snd a)) ret 

tmpList :: Int -> [(Int, Int)] -> [(Int, Int)] -> [(Int, Int)]
tmpList _ [] ret = sortOn fst ret
tmpList n (a:as) ret = tmpList n as ((n - (snd a - 1), n - (fst a - 1)):ret)