l=int(input()) n=int(input()) w=list(map(int,input().split())) w.sort() sum=0 for i in range(len(w)): sum+=w[i] if sum>=l: print(i) break