N, W = gets.split.map(&:to_i)
dp = Array.new(N+1){Array.new(W+1, 0)}
lists = []
N.times do |i|
  lists << gets.split.map(&:to_i)
end
1.upto(N) do |i|
  1.upto(W) do |j|
    if j >= lists[i-1][0]
      dp[i][j] = [dp[i-1][j], dp[i-1][j - lists[i-1][0]] + lists[i-1][1]].max
    else
      dp[i][j] = dp[i-1][j]
    end
  end
end
puts dp[N][W]