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