L=int(input()) N=int(input()) W=list(map(int,input().split())) W.sort() X=0 k=0 while (X<=L) and (k<=N): X+=W[k] k+=1 print(k-1)