n,t=gets.split.map(&:to_i)
ab=[]
n.times do
  ab << gets.split.map(&:to_i)
end
ab.sort!
dp=[0]*t
dn=[]
t.times do |i|
  dn << []
end
i=0
ab.each do |a,b|
  (t-1).downto(a) do |j|
    if dp[j]<b+dp[j-a]
      dp[j]=b+dp[j-a]
      dn[j]=dn[j-a]|[i]
    end
  end
  i+=1
end
dn[-1].sort!.reverse!
dn[-1].each do |ddn|
  ab.delete_at(ddn)
end
m=0
ab.each do |a,b|
  m=b if b>m
end
puts dp[-1]+m
