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

(1..n).each{|ni|
  a,b = list[ni]
  (0..t-1).each{|ti|
    dp[ni][ti] = if ti-a >= 0 && dp[ni-1][ti] < dp[ni-1][ti-a]+b
      dp[ni-1][ti-a]+b
    else
      dp[ni-1][ti]
    end
  }
}
p (1..n).map{|ni|dp[ni-1][t-1]+list[ni][1]}.max