total = int(input()) ct = int(input()) lst = [int(i) for i in input().split()] lst.sort() s = 0 for idx, val in enumerate(lst) : if s + val > total : print(idx) break else: s += val