s=int(input()) input() b=sorted(list(map(int,input().split()))) c=len(b) for (i,x) in enumerate(b): s-=x if s<0: c=i break print(c)