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