L = int(input()) N = int(input()) W = input().split() i = 0 W.sort() for i in range(N): if L > int(W[i]): L = L - int(W[i]) i += 1 else: break print(i)