import kotlin.math.max

fun main(args: Array<String>) {
    val (n, t) = readLine()!!.split(" ").map { it.toInt() }.let { Pair(it[0], it[1]) }
    val ab = (1 .. n).map {
        readLine()!!.split(" ").map { it.toInt() }.let { Pair(it[0], it[1]) }
    }.sortedBy {
        it.first
    }
    var dp = IntArray(t) { if (it == t - 1) 0 else -1 }
    var ret = 0
    for ((a, b) in ab) {
        val newdp = dp.toMutableList()
        for (j in 0 .. t - 1) {
            if (dp[j] >= 0) {
                ret = max(ret, dp[j] + b)
                if (j - a >= 0) {
                    newdp[j - a] = max(newdp[j - a], dp[j] + b)
                }
            }
        }
        dp = newdp.toIntArray()
    }
    println(ret)
}
