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