L = int(input()) N = int(input()) W = list(map(int, input().split())) w = sorted(W) score = 0 for i in range(N): if score + w[i] <= L: score += w[i] else: print(i) break if i == N-1: print(i+1)