n, t = gets.split.map(&:to_i)
ab = n.times.map {gets.split.map(&:to_i)}.sort_by{|e| e[0]}

dp = Array.new(t)
dp[0] = max = 0
dp[ab[0][0]] = max = ab[0][1] if ab[0][1] < t
ans = ab[0][1]
ab.shift

ab.each do |a, b|
    y = 0
    (t - a - 1).downto(0) do |i|
        next if dp[i].nil?
        z = dp[i] + b
        dp[i+a] = z if dp[i+a].nil? || dp[i+a] < z
        y = z if y < z
    end
    ans = max + b if ans < max + b
    max = y if max < y
end

puts ans
