L=int(input()) N=int(input()) W=list(map(int,input().split())) W.sort() #print(L,N,W) ans=0 while W: L-=W.pop(0) if L<0: break ans+=1 print(ans)