L = int(input()) N = int(input()) W = sorted(list(map(int, input().split()))) S = 0 C = 0 for w in W: if S + w <= L: S += w C += 1 else: break print(C)