L = int(input()) N = int(input()) W_n = list(map(int, input().split())) W_n.sort() box = [] for W_i in W_n: if sum(box) > L: box.pop() break box.append(W_i) print(len(box))