l=int(input()) n=int(input()) w=list(map(int,input().split())) w_new=sorted(w) for i in range(n): l-=w_new[i] if l<0: print(i) break print(n)