L = int(input()) N = int(input()) W = sorted([int(x) for x in input().split()]) I = 0 for n in W: if L - n >= 0: L -= n I += 1 else: break print(I)