n,t = gets.split.map(&:to_i)
a = []
max_t=0
n.times do |i|
    a.push(gets.split.map(&:to_i))
    max_t = a[i][0] if a[i][0]>max_t
end

dp = Array.new(t+max_t, 0)
a.sort.each do |tt,pp|
    (t+tt-1).downto(tt) {|i| dp[i] = pp+dp[i-tt] if dp[i-tt]+pp>dp[i]}
end

p dp.max
