n,t = gets.split.map(&:to_i)
list = (1..n).map{gets.split.map(&:to_i)}.sort
dp = [0]*(t+3001)

p list.map{|a,b|
  predp = dp.dup
  (0..t-1).each{|ti|
    if dp[tia=ti+a] < predpb=predp[ti]+b
      dp[tia] = predpb
    end
  }
  predp[t-1]+b
}.max