L = int(input()) input() li = [] for W in sorted(map(int, input().split())): if sum(li) + W > L: break li.append(W) print(len(li))