N,T = gets.chomp.split(" ").map(&:to_i)
list = []
N.times do
  list << gets.chomp.split(" ").map(&:to_i)
end
manzoku = Array.new(6000,0)
result = []
for food in list.sort
  buffer = T.downto(1).map{|turn|
    end_turn = turn + food[0]
    manzoku[end_turn] = [manzoku[end_turn], manzoku[turn] + food[1]].max
    }
  result += buffer
end
puts result.max