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

if ab[0][0] >= t
    puts ab.max_by{|e| e[1]}[1]
    exit
end

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

ab.each_with_index do |(a, b), i|
    m = 0
    dp[i].each do |k, v|
        dp[i+1][k] = v if !dp[i+1][k] || dp[i+1][k] < v
        m = v + b if m < v + b
        dp[i+1][k+a] = v + b if k + a < t && (!dp[i+1][k+a] || dp[i+1][k+a] < v+b)
    end
    ans = m if ans < m
end

puts ans