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