N, T = gets.split.map(&:to_i)
ABs = readlines.map{|l| l.split.map(&:to_i)}

dp = Array.new(T + ABs.map(&:first).max + 1, 0)
ABs.sort.each do |a, b|
  (T - 1).downto(0) do |t|
    dp[t + a] = dp[t] + b if dp[t + a] < dp[t] + b
  end
end
puts dp.max