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+3000)}

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