L=int(input()) N=int(input()) W = input().split() W.sort(key=int) for i in range(N): if L>=int(W[i]): L-=int(W[i]) else: print(i) break