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