n, t = gets.chomp.split.map(&:to_i)
dp = Array.new(n + 1) { Hash.new(0) }
dp[0][t] = 0

n.times do |w|
  a, b = gets.chomp.split.map(&:to_i)
  k = dp[w].keys
  k.each do |rt|
    dp[w + 1][rt] = [dp[w + 1][rt], dp[w][rt]].max
    if rt > 0
      dp[w + 1][rt - a] = [dp[w + 1][rt - a], dp[w][rt] + b].max
    end
  end
end
puts dp[n].values.max