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