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