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