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

dp = Array.new(T)
ans = 0
dp[0] = 0
F.each{|a, b|
  (T-1).downto(0){|n|
    next if dp[n].nil?
    if n+a < T then
      if dp[n+a].nil? || dp[n+a] < dp[n] + b then
        dp[n+a] = dp[n] + b
      end
    else
      ans = dp[n] + b if ans < dp[n] + b
    end
  }
}

dp << ans
puts dp.compact.max
