{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
import qualified Data.ByteString.Char8 as BS
import           Data.List             (sortOn)
import           Data.Maybe            (fromJust)

main :: IO ()
main = do
  [n, m] <- map readInt . BS.words <$> BS.getLine
  abs <- map readInt2 . BS.lines <$> BS.getContents
  print $ solve n m abs

solve :: Int -> Int -> [(Int, Int)] -> Int
solve _ _ abs = fst $ foldl f (0, 0) abs' where
  abs' =  sortOn snd abs
  f (c, x) (a, b)
    | a < x     = (c, x)
    | otherwise = (c + 1, b)

readInt :: BS.ByteString -> Int
readInt = fst . fromJust . BS.readInt

readInt2 :: BS.ByteString -> (Int, Int)
readInt2 s = (a, b) where
  [a, b] = map readInt $ BS.words s
