n, mw = gets.chomp.split.map(&:to_i)
sum = []
w, v = gets.chomp.split.map(&:to_i)
mw.downto(0) do |i|
  if i >= w
    sum[i] = v
  else
    sum[i] = 0
  end
end

(n-1).times do
  w, v = gets.chomp.split.map(&:to_i)
  mw.downto(0) do |i|
    sum[i] = sum[i-w] + v if i >= w && sum[i] < sum[i-w] + v
  end
end

puts sum[mw]
