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