object Main extends App {
  val Array(n, weight) = io.StdIn.readLine().split(' ').map(_.toInt)
  val items = Array.fill(n)(io.StdIn.readLine().split(' ').map(_.toInt))
  val dp: Array[Array[Long]] = Array.fill(n+1)(Array.fill(weight+1)(-1))
  dp(0)(0) = 0

  for (i <- 0 until n)
    for (w <- (0 to weight).filter(dp(i)(_) != -1)) {
      if (w+items(i)(0) <= weight) {
        val current = dp(i+1)(w+items(i)(0))
        val tmp = dp(i)(w) + items(i)(1)
        if (current < tmp) dp(i+1)(w+items(i)(0)) = tmp
      }
      if (dp(i+1)(w) < dp(i)(w)) dp(i+1)(w) = dp(i)(w)
    }
  println(dp(n).max)
}