box_width = gets.to_i number = gets.to_i blocks = gets.chomp.split(" ") blocks.sort! i = 0 width = 0 while true width += blocks[i].to_i if width >= box_width break else i += 1 end end puts i