#coding:utf-8 import itertools L = int(raw_input()) N = int(raw_input()) W = raw_input() listW=W.split(" ") for i in range(1,N+1): result = list(itertools.combinations(listW,i)) len_res = len(result) for k in range(len_res): int_res = map(int,result[k]) blocks = sum(int_res) if L>=blocks: ans = i else: continue print ans