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