width = gets.to_i num = gets.to_i blocks = gets.split.map{|s|s.to_i}.sort t = 0 n = 0 for b in blocks t += b if t > width break end n += 1 end p n