def max(a,b); a > b ? a : b;end
N,T = gets.split.map(&:to_i)
F = N.times.map{ gets.split.map(&:to_i) }.sort

dp = Array.new(6010, 0)
F.each do |a,b|
  (0 ... T).reverse_each do |t|
    dp[t + a] = max(dp[t + a], dp[t] + b)
  end
end
puts dp.max