import qualified Data.ByteString.Char8 as BS
import Control.Monad
import Data.List

toTuple :: [Int] -> (Int, Int)
toTuple [a,b] = (b,a)

solve :: [(Int,Int)] -> Int -> Int -> Int
solve [] memo bridges = bridges
solve ((to,from):xs) memo bridges = 
  if memo `elem` [from..to] then
    solve xs memo bridges
  else 
    solve xs (to-1) (bridges+1)

main = do
  [n,m] <- map read . words <$> getLine :: IO [Int]
  xs <- replicateM m (toTuple . map (read . BS.unpack). BS.words <$> BS.getLine)
  print $ solve (sort xs) 0 0