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