L=int(input()) N=int(input()) W=sorted([int(i) for i in input().split()]) cnt=0 for i in range(N): if cnt+W[i]<=L: cnt+=W[i] else: print(i) exit() print(N)