N,T = gets.chomp.split(" ").map(&:to_i)
list = []
N.times do
list << gets.chomp.split(" ").map(&:to_i)
end
manzoku = {0=>0}
result = []
for food in list.sort
  for i in (1..T).to_a.reverse
    total_time = i + food[0]
    manzoku[total_time] ||= 0
    manzoku[i] ||= 0
    manzoku[total_time] = [manzoku[total_time], manzoku[i] + food[1]].max
    result << manzoku[total_time]
  end
end
puts result.max