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