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