L = int(input()) N = int(input()) W = list(map(int, input().split())) t = 0 for i, w in enumerate(sorted(W)): if t+w > L: print(i) break t += w else: print(N)