L, N, *W = map(int, open(0).read().split()) W.sort() sum = 0 for i, w in enumerate(W, 1): sum += w if sum > L: print(i - 1) exit() elif sum == L: print(i) exit() print(N)