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_by(&:reverse)
dp = Array.new(N + 1){ Array.new(6060, 0) }

F.each_with_index do |(a, b), i|
  (0 ... T).reverse_each do |t|
    dp[i + 1][t + a] = max(dp[i][t] + b, dp[i][t + a])
  end
end
puts dp[N].max
