import java.util.Scanner
import scala.math._

object Main extends App {
  val sc = new Scanner(System.in)
  val N, W = sc.nextInt
  val wv = Array.fill(N, 2)(sc.nextInt)

  val dp = Array.fill(N+1, W+1)(0L)

  for (i <- 1 to N) {
    val Array(wi, vi) = wv(i-1)
    for (w <- 0 to W) {
      dp(i)(w) = if (w >= wi) max(dp(i-1)(w), dp(i-1)(w-wi)+vi) else dp(i-1)(w)
    }
  }
  println(dp.last.last)
}
