

import Foundation


class Scanner {
    static func readInt() -> Int {
        return Int(readLine()!)!
    }
    
    static func readIntArr() -> [Int] {
        return readLine()!.split(separator: " ").map { Int($0)! }
    }
    
    static func readM(_ n: Int) -> [[Int]] {
        var res = [[Int]]()
        for _ in 0..<n {
            res.append(readIntArr())
        }
        return res
    }
    
    static func readUknownIntMat() -> [[Int]] {
        var res = [[Int]]()
        while let line = readLine() {
            res.append(line.split(separator: " ").map { Int($0)! })
        }
        return res
    }
    
    static func readString() -> String {
        return readLine()!
    }
}

class Printer {
    static func printIntArray(_ arr: [Int]) {
        print(arr.map { String($0) }.joined(separator: " "))
    }
}

let nt = Scanner.readIntArr()
let n = nt[0], t = nt[1]
let arr = Scanner.readM(n)


func find(_ cv: [[Int]], _ t: Int, _ n: Int) -> Int {
    var dp = [[Int]](repeating: [Int](repeating: 0, count: n+1), count: t+1)
    let costVal = cv.sorted(by: { $0[0] < $1[0] })
    var res = 0
    for i in stride(from: 0, to: t, by: 1) {
        for j in stride(from: 0, to: n, by: 1) {
            dp[i][j+1] = max(dp[i][j+1], dp[i][j])
            if(i + costVal[j][0] < t) {
                dp[i + costVal[j][0]][j+1] = max(dp[i + costVal[j][0]][j], costVal[j][1] + dp[i][j])
            }
            res = max(res, dp[t-1][j] + costVal[j][1])
        }
    }
    
//    print(dp)
    return res
}

print(find(arr, t, n))
