L=int(input()) N=int(input()) W=list(map(int,input().split())) W=sorted(W) S=0 count=0 for i in range(N): if L < S+W[i]: break S+=W[i] count+=1 print(count)