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