n, W = gets.split.map(&:to_i)
w, v = n.times.map { gets.split.map(&:to_i) }.transpose
dp = Array.new(n + 1) { Array.new(W + 1, 0) }
n.times do |i|
  (W + 1).times do |j|
    dp[i + 1][j] = dp[i + 1][j] > dp[i][j] ? dp[i + 1][j] : dp[i][j]
    dp[i + 1][j] = dp[i + 1][j] > dp[i][j - w[i]] + v[i] ? dp[i + 1][j] : dp[i][j - w[i]] + v[i] if j >= w[i]
  end
end
p dp[n][W]
