L=int(input()) N=int(input()) p=sorted([int(n) for n in input().split()])+[0] m=0 for i in range(N+1): m+=p[i] if m>L: break print(i)