i=input L=int(i()) l=int(i())-1 W=sorted(map(int,i().split())) s=sum(W) while s>L:s-=W[l];l-=1 print(l+1)