L=int(input()) N=int(input()) p=sorted([int(n) for n in input().split()]) m=0 for i in range(N): m+=p[i] if m>L: break print(i)