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