import java.math.*

fun main(args: Array<String>) {
    val (N, T) = readInputLine().split(" ").map { it.toInt() }
    
    val dishes = Array(N) { Pair(0, 0) }

    for (i in 0 until N) {
        val (A, B) = readInputLine().split(" ").map { it.toInt() }
        dishes[i] = Pair(A, B)
    }
    
    val dp1 = Array(N + 2) { IntArray(T) }
    val dp2 = Array(N + 2) { IntArray(T) }
    
    for (i in 1 until T) {
        for (j in 1..N) {
            if (dishes[j - 1].first <= i) {
                dp1[j][i] = Math.max(dp1[j - 1][i], dp1[j - 1][i - dishes[j - 1].first] + dishes[j - 1].second)
            } else {
                dp1[j][i] = dp1[j - 1][i]
            }
            
            if (dishes[N - j].first <= i) {
                dp2[N - j + 1][i] = Math.max(dp2[N - j + 2][i], dp2[N - j + 2][i - dishes[N - j].first] + dishes[N - j].second)
            } else {
                dp2[N - j + 1][i] = dp2[N - j + 2][i]
            }
        }
    }

    var ans = 0

    for (i in 0 until T) {
        for (j in 1..N) {
            ans = Math.max(ans, dp1[j - 1][i] + dp2[j + 1][T - 1 - i] + dishes[j - 1].second)
        }
    }

    println(ans)
}

fun readInputLine(): String {
    return readLine()!!
}

