import itertools L = int(input()) N = int(input()) W = list(map(int, input().split())) W.sort() l = 0 for i in range(0, N+1): if(sum(W[:i]) > L): break l = i print(l)