N, T = gets.chomp.split(" ").map(&:to_i)
F = Array.new(N).map{
  gets.chomp.split(" ").map(&:to_i)
}

dp = Array.new(T, 0)
ans = 0
bef = [0]
F.each{|a, b|
  nxt = []
  bef.each{|n|
    if n+a < T then
      if dp[n+a] < dp[n] + b then
        dp[n+a] = dp[n] + b
        nxt << n+a
      end
    else
      ans = dp[n] + b if ans < dp[n] + b
    end
  }
  bef = (bef | nxt).sort.reverse
}

dp << ans
puts dp.max
