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