fun main(args: Array<String>) {
    val (N, T) = readLine()!!.split(" ").map{it.toInt()}
    val P = Array(N) {
        val a = readLine()!!.split(" ").map{it.toLong()}
        Pair(a[0].toInt(), a[1])
    }.sortedBy { it.first }

    val dp = Array(6010) { 0L }

    for (i in P.indices) {
        for (j in T - 1 downTo 0) {
            dp[j + P[i].first] = Math.max(dp[j + P[i].first], dp[j] + P[i].second)
        }
    }

    println(dp.max())
}
