L=int(input()) N=int(input()) ws=list(map(int,input().split())) ws.sort() total=0 for i,w in enumerate(ws): total+=w if total>L:break else: i=N print(i)