L = int(input()) N = int(input()) W = list(map(int,input().split())) W = sorted(W) ans = N for i in range(N): if W[i] <= L: L-=W[i] else: ans = i break print(ans)