def main(input = $stdin)
  n, w = input.gets.split(" ").map(&:to_i)
  goods = []
  n.times do
    goods << input.gets.split(" ").map(&:to_i)
  end
  arr = Array.new(w + 1, nil)
  arr[0] = 0
  goods.each{|good|
    #arr[0..w - good[1]].each_with_index{|i, idx|
    #  p [arr, i, idx]
    for idx in 0..w - good[1]
      if arr[idx] and (!arr[idx + good[1]] or arr[idx + good[1]] < arr[idx] + good[0])
        arr[idx + good[1]] = arr[idx] + good[0]
      end
    end
  }
  puts arr.select{|i|i}.max
end
main