L=raw_input() N=raw_input() w=raw_input() W=map(int, w.split()) c=0 mx=0 W.sort() for a in W: c+=a if c<=int(L): mx+=1 print mx