l=int(input()) n=int(input()) *w,=map(int,input().split()) w.sort() i=0 while i<=n: if sum(w[:i])>l: print(i-1) break elif sum(w[:i])==l: print(i) break i+=1 else: print(i-1)