import Data.Char
import Data.List
import qualified Data.ByteString.Char8 as B
import qualified Data.Vector.Unboxed as V
import qualified Data.Vector.Algorithms.Intro as VA
main=print.solve.map((\[a,b]->(a,b)).unfoldr(B.readInt.B.dropWhile isSpace)).B.lines=<<B.getContents
solve((n,m):ab)=fst.V.foldr f(0,maxBound)$V.modify VA.sort$V.fromList ab
f(a,b)(k,i)=if i<b then (k,i) else (k+1,a)