N, W = gets.split.map(&:to_i)
lists = []
N.times do
  lists << gets.split.map(&:to_i)
end
# p lists
# lists.sort_by!{|v, w| -v.to_f / w}
# p lists
dp = Array.new(W+1, -1)
dp[0] = 0
ans = 0
# binding.pry
N.times do |k|
  lists[k][1].upto(W) do |i|
    if dp[i - lists[k][1]] != -1
      if dp[i] < dp[i - lists[k][1]] + lists[k][0]
        dp[i] = dp[i - lists[k][1]] + lists[k][0]
      end
      if ans < dp[i]
        ans = dp[i]
      end
    end
  end
end
puts ans
