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