import Control.Monad
import Data.List (sort)

readIntLine :: IO ([Int])
readIntLine = do
    x <- getLine
    return $ map (read :: String -> Int) $ words x

read2Ints :: IO ((Int, Int))
read2Ints = do
    x <- readIntLine
    return (head x, head.tail $ x)

main :: IO ()
main = do
    [n,m] <- readIntLine
    cardsU <- replicateM m read2Ints
    let cards = sort cardsU
    print $ fst $ needed_cards cards

needed_cards [] = (0, 1000000000)
needed_cards ((l,r):cards)
    | r >= lastcard = (res, lastcard)
    | otherwise     = (res + 1, l)
        where (res, lastcard) = needed_cards cards
