L=int(input()) N=int(input()) W=sorted(map(int, input().split())) i=s=0 while s<=L: s+=W[i] i+=1 print(i-1)