import Control.Monad
import Control.Monad.ST
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
listToTuple (x : y : _) = (x, y)

main = do
    [n, t] <- getIntList
    abs <- sort . map listToTuple <$> replicateM n getIntList
    dp <- VUM.replicate 3001 0
    ans <- forM abs $ \(a, b) -> do
               b' <- VUM.read dp (t - 1)
               forM_ [3000,2999..0] $ \i -> do
                   when (i - a >= 0) $ do
                       s <- VUM.read dp i
                       t <- VUM.read dp (i - a)
                       VUM.write dp i $ max s (t + b)
               return $ b' + b
    print $ maximum ans