L=int(input()) N=int(input()) W=input().split() W.sort() i=0 count=0 while L>=i: i+=int(W[count]) count+=1 print(count-1)