L=int(input()) N=int(input()) m=0 for i,w in enumerate(sorted([int(w) for w in input().split()])): m+=w if m>L: print(i) break if m<=L: print(N)