L=int(input()) N=int(input()) X=list(map(int, input().split())) X.sort() y=0 r=0 for x in X: y+=x if y > L: break r+=1 print(r)