L=int(input()) N=int(input()) #W=[0]*N W=list(map(int,input().split())) W=sorted(W) S=0 i=0 while L >= S+W[i]: S+=W[i] i+=1 print(i-1)