c=0 a=0 I=input l=int(I()) n=int(I()) w=list(map(int,(I().split()))) w.sort() for i in range(n): if a+w[i] <= l: a+=w[i] c+=1 else: break print(c)