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