import Data.List
import Control.Monad
import qualified Data.IntMap  as IM

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 = go IM.empty 0 abs where
  go set _ [] = sum $ map (uncurry (*)) $ IM.toList set
  go set n (ab:abs) = go next newn abs where
    newn = m-fst(head ab)+1
    next = foldl inner (IM.insert 0 (newn-n) set) $ f ab
    inner set (n,b) = insertIfLarge b set
  abs = groupBy (\(x,_)(y,_)->x==y)
      $ sortBy (\(x,_)(y,_)->compare y x)
      $ sortBy (\(_,x)(_,y)->compare y x) ab
  f a@((n,_):_) = take (m-n+1) a

insertIfLarge a set = case IM.lookupMin set of
  Nothing -> set
  Just (k, 1) -> if a > k then IM.insertWith(+) a 1 $ IM.delete k set else set
  Just (k, _) -> if a > k then IM.insertWith(+) a 1 $ IM.adjust(subtract 1) k set else set