import Data.List
import Control.Monad

main = do
  [n,m] <- map read.words<$>getLine
  ab <- replicateM n $ (\[a,b]->(read a,read b)).words<$>getLine
  print $ solve n m ab

solve :: Int -> Int -> [(Int,Int)] -> Int
solve n m ab  = sum $ take m
      $ sortBy (flip compare)
      $ concatMap (map g.f)
      $ groupBy (\(x,_)(y,_)->x==y)
      $ sortBy (\(x,_)(y,_)->compare y x)
      $ sortBy (\(_,x)(_,y)->compare y x) ab where
  f a@((n,_):_) = take (m-n+1) a
  g (_,b) = b