{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}

import Control.Applicative
import Control.Monad
import Control.Arrow
import Data.List
import Data.Maybe
import Data.Char
import qualified Data.ByteString.Char8 as B
import Text.Printf

import Debug.Trace

import GHC.Exts

readInt = ( readLn :: IO Int )
readInts = map ( read :: String -> Int ) . words <$> getLine

getList = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = do
	[ n, m ] <- readInts
	ps <- sortWith snd . map ( id *** pred ) . map mp <$> replicateM m readInts
	print ps
	print $ solve ps

solve [] = 0
solve ( ( a, b ) : ps ) = 1 + solve ( dropWhile ( \( x, y ) -> x <= b && b <= y ) ps )