def max(a,b); a > b ? a : b; end
def max3(a,b,c); max(max(a,b),c); end
  
N,T = gets.split.map(&:to_i)
A = N.times.map{ gets.split.map(&:to_i).reverse }.sort
dp = Array.new(N + 1){ Array.new(T + 3030, 0) }
A.each_with_index do |(v,t_),i|
  (1 ... T).each do |t|
    dp[i + 1][t] = max3(dp[i][t], dp[i][t - t_] + v, dp[i + 1][t - 1]) if t - t_ >= 0
  end
end
puts dp[N - 1][T - 1] + A[N - 1][0]