i=input L=int(i()); i() W=sorted(map(int,i().split())) c,w=0,0 while c<L: c+=W[w];w+=1 if w==len(W):break if c<=L:print(w) else:print(w-1)