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