
N,T=gets.split.map(&:to_i)

menu=N.times.map{ gets.split.map(&:to_i)}
maxs=Array.new(T+3001,0)

menu.each do |m|
  a,b=m
  new_maxs=maxs.dup
  T.times do |t|
    temp=maxs[t]+b
    new_maxs[t+a]=temp if temp>new_maxs[t+a]
  end
  maxs=new_maxs
end
max=0
(T+3001).times do |t|
  max=maxs[t] if maxs[t]>max
end
p max
