import Control.Monad
import Data.List

main = do
  li <- getLine
  let [n,m] = map read $ words li
  bcs <- sequence $ replicate n (do
    li <- getLine
    let [a,b] = map read $ words li
    return (b,m-a)
    )
  let ans = compute m bcs
  print ans

compute :: Int -> [(Int,Int)] -> Int
compute m bcs = fst $ foldl' step (0,([],0)) bcs1
  where
    bcs1 = reverse $ sort bcs
    step a@(acc,(cs,l)) (b,c)
      | l == m = a
      | valid cs1 = (acc+b,(cs1, succ l))
      | otherwise = a
      where
        cs1 = insert c cs
    valid xs = and $ zipWith (>=) xs [0..]

