N, T = gets.chomp.split.map(&:to_i)

eggs = []
N.times { eggs << gets.chomp.split.map(&:to_i) }

dp = [0] * 6001

eggs.each do |egg|
  (T - 1).downto(0) do |i|
    dp[i + egg[0]] = [dp[i + egg[0]], dp[i] + egg[1]].max
  end
end

puts dp.max
