import sys L = input() N = input() W = map(int, raw_input().split()) s = 0 for i, x in enumerate(sorted(W)): if (s + x <= L): s += x else: print i sys.exit() print len(W)