L = int(input()) N = int(input()) W = list(map(int, input().split())) W.sort() s = 0 for i, a in enumerate(W): s += a if s > L: break print(i)