--{-# LANGUAGE OverloadedStrings #-}
--{-# LANGUAGE OverloadedLists   #-}
{-# LANGUAGE BangPatterns      #-} --引数に!
{-# LANGUAGE MultiWayIf        #-}
{-# LANGUAGE TupleSections     #-}

import Data.Bits
import Data.Foldable (foldlM,foldrM)
import Data.Maybe (fromJust)
import Data.List
import Data.Array.Unboxed
import Data.Array.MArray
import Data.Array.ST
import Control.Monad
import Control.Monad.State
import Control.Monad.ST
import qualified Data.ByteString.Lazy.Char8 as B

solve :: Int -> Int -> Int -> [(Int,Int)] -> Int
solve n m i [] = 0
solve n m i ((a,b):ls) = if i+a <= m then b+(solve n m (i+1) ls) else solve n m i ls

main :: IO ()
main = do
  [n,m] <- map read.words <$> getLine :: IO [Int]
  ls <- replicateM n $ do
    [a,b] <- map read. words <$> getLine :: IO [Int]
    return (a,b)

  print $ solve n m 0 (sortOn (\(a,b) -> (-b,-a)) ls)
