aa=int(input()) bb=int(input()) cc=list(map(int,input().split(" "))) dd=0 ee=0 ff=0 for i in range(0,bb): for j in range(i+1,bb): if cc[i]>cc[j] : dd=cc[i] cc[i]=cc[j] cc[j]=dd for i in range(0,bb): ee+=cc[i] if ee<=aa: ff+=1 else: break print(ff)