L = input() N = input() W = map(int, raw_input().split()) sum = 0 num = 0 for i in xrange(N): tmp = min(W) W.remove(tmp) sum += tmp if sum <= L: num += 1 else: break print num