import java.util.*
import kotlin.math.*

fun main() {
    val (n, w) = readIntList()
    val items = List(n) { readIntList() }

    val dp = List(n + 1) { MutableList(w + 1) { 0L } }

    for (i in 0 until n) {
        for (j in 0..w) {
            dp[i + 1][j] = if (j >= items[i][0]) {
                max(dp[i][j - items[i][0]] + items[i][1], dp[i][j])
            } else {
                dp[i][j]
            }
        }
    }
    println(dp[n][w])
}


fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)