N,T = gets.chomp.split(" ").map(&:to_i)
list = []
N.times do
list << gets.chomp.split(" ").map(&:to_i)
end
manzoku = {0=>[0,0]}
for food in list
  for time in manzoku.keys
    next unless time < T
    new_time = time + food[0]
    if manzoku[new_time]
      manzoku[new_time][1] = manzoku[time][0] + food[1]
    else
      manzoku[new_time] = [0, manzoku[time][0] + food[1]]
    end
  end
  for buff in manzoku.values
    buff[0] = [buff[0], buff[1]].max
    buff[1] = 0
  end
end
puts manzoku.values.sort_by{|v| v[0]}.pop[0]