n, t = $stdin.readline.chomp.split.map(&:to_i)
d = Array.new(n) { $stdin.readline.chomp.split.map(&:to_i) }.sort_by! {|a, _| a }
dp = Array.new(n + 1) { Hash.new(0) }
dp[0][0] = 0

res = 0
n.times do |i|
  a, b = d[i]
  dp[i].each do |k, v|
    if k < t
      dp[i + 1][k] = [dp[i + 1][k], v].max
      dp[i + 1][k + a] = (v + b) if dp[i + 1][k + a] < (v + b)
      res = dp[i + 1][k + a] if res < dp[i + 1][k + a]
    end
  end
end
puts res