inputs = STDIN.readlines.map(&:chomp) l = inputs[0].to_i n = inputs[1].to_i ws = inputs[2].split(/\s+/).map(&:to_i) blocks = length = 0 ws.sort.each do |w| length += w break if length > l blocks += 1 end puts blocks