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

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

ab.each_with_index do |(a, b), i|
    m = 0
    dp[i].each_with_index do |x, j|
        next if !x
        dp[i+1][j] = x if !dp[i+1][j] || dp[i+1][j] < x
        m = x + b if m < x + b
        dp[i+1][j+a] = x + b if j + a < t
    end
    ans = m if ans < m
end

puts ans