L=int(input()) N=int(input()) W=sorted(map(int, input().split())) w=0 ans=0 for i in range(N): w+=W[i] if w > L: break ans += 1 print(ans)