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

eggs = []
N.times { eggs << gets.chomp.split.map(&:to_i) }
eggs.sort! { |a, b| a[0] <=> b[0] }

dp = [0] * 6001

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

puts dp.max
