L = gets.to_i N = gets.to_i W = gets.split.map(&:to_i) widths = W.sort! ans = [] widths.each do |width| ans << width break if ans.sum >= L end puts ans.count - 1