N,T = gets.chomp.split(" ").map(&:to_i)
list = []
N.times do
list << gets.chomp.split(" ").map(&:to_i)
end
manzoku = {0=>[0,0]}
list.each_with_index{|food, i|
  now,nex = i%2,(i+1)%2
  for time in manzoku.keys
    next unless time < T
    total_time = time + food[0]
    if manzoku[total_time] and manzoku[total_time][now]
      if manzoku[time][now] + food[1] > manzoku[total_time][now]
        manzoku[total_time][nex] = manzoku[time][now] + food[1]
      else
        manzoku[total_time][nex] = manzoku[total_time][now]
      end
    else
      manzoku[total_time] = []
      manzoku[total_time][now] = food[1]
      manzoku[total_time][nex] = manzoku[time][now] + food[1]
    end
  end
  }
puts manzoku.values.sort_by{|v| v[0]}.pop[0]