L = int(input()) N = int(input()) W = list(map(int, input().split())) from itertools import combinations for i in reversed(range(1, N+1)): for j in combinations(W, i): if sum(j) <= L: print(i) exit()