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

main=do
 [n,m]<-map read.words<$>getLine
 ba<-replicateM m ((\(a:[b])->(b,a)).map (read.BS.unpack).BS.words<$>BS.getLine)
 print (f m (sort ba) 0 0)
  where f 0 _ _ i = i
        f m ((b,a):ba) j i = if a>=j then (f (m-1) ba b (i+1)) else (f (m-1) ba j i)