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