object Main extends App {

  import scala.io.StdIn._

  val Array(n, weightMax) = readLine.trim.split(' ').map(_.toInt)
  val maxMemo = Array.tabulate(weightMax + 1){ _ ⇒ Long.MinValue}.also{arr ⇒ arr(0) = 0L}
  for (_ ← 0 until n){
    val Array(w, v) = readLine.trim.split(' ').map(_.toInt)
    for (prev ← (0 to weightMax - w).reverse) {
      if (maxMemo(prev) != Long.MinValue && maxMemo(prev + w) < maxMemo(prev) + v) {
        maxMemo(prev + w) = maxMemo(prev) + v
      }
    }
  }
  println(maxMemo.max)
  case class Goods(weights: Long, value: Long)
  implicit class Extend[T](value: T){
    def also(func: T ⇒ Unit): T = {func(value); value}
    def let[A](func: T ⇒ A): A = func(value)
  }
}