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