l = gets.to_i n = gets.to_i w = gets.split.map(&:to_i) index = nil w.sort!.each_with_index do |width, i| l -= width if (l < 0) index = i break end end if index puts index else puts n end