import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min

fun main() {
  val (n,w) = readLine()!!.split(' ').map { it.toInt() }
  val dp = LongArray(w+1){0}

  for (i in 0 until n){
    val (weight, cost) = readLine()!!.split(' ').map { it.toInt() }
    for (j in (w-weight) downTo 0){
      dp[j+weight] = max(dp[j+weight], dp[j]+cost)
    }
  }
  var ans = 0L
  dp.forEach { ans = max(ans, it) }
  println(ans)
}