import itertools L = int(input()) N = int(input()) W = list(map(int,input().split())) r = [] for n in range(1,len(W)+1) : for conb in itertools.combinations(W, n): A = list(conb) AA = sum(A) if AA <= L : nag = len(A) result.append(nag) print(max(r))