L, _ = int(input()), input() ws = list(map(int,input().split())) counter, total= 0, 0 for i in sorted(ws): if L < (total + i): break else: counter+=1 total += i print(counter)