n, w_ub = gets.chomp.split.map(&:to_i)

dp = Array.new(n + 1) { Array.new(w_ub + 1, 0) }# i - 1 <= 
n.times do |i|
  w, v = gets.chomp.split.map(&:to_i)
  (0..w_ub).each do |j|
    if j >= w
      dp[i + 1][j] = [dp[i][j], dp[i][j - w] + v].max
    else
      dp[i + 1][j] = dp[i][j]
    end
  end
end

puts dp[n][w_ub]