n,t = gets.split.map(&:to_i)
list = (1..n).map{gets.split.map(&:to_i)}.sort
dp = [0]*(t)
ans = 0
list.each{|a,b|
  predp = dp.dup
  (0..t-1-a).each{|ti|
    if dp[tia=ti+a] < predpb=predp[ti]+b
      dp[tia] = predpb
    end
  }
  if ans < tmpans=predp[t-1]+b
    ans = tmpans
  end
}
p ans