n,t = gets.split.map(&:to_i)
list = [0,0]+(1..n).map{gets.split.map(&:to_i)}.sort_by{|a,b|[a,-b]}

dp = (0..n).map{[0]*t + [-10e9]*3000}

(1..n).each{|ni|
  (1..t-1).each{|ti|
    dp[ni][ti] = [
      dp[ni][ti-1],
      dp[ni-1][ti],
      dp[ni-1][ti-list[ni][0]]+list[ni][1]
    ].max
  }
}
p (1..n-1).map{|ni|dp[ni][t-1]+list[ni+1][1]}.max