L = int(input()) N = int(input()) W = list(map(int, input().split())) W.sort() for i in range(N): if sum(W[:i+1]) > L: print(i) break