import itertools import bisect L = int(input()) _N = int(input()) W = [int(i) for i in input().split()] W.sort() cnt = 0 W = list(itertools.accumulate(W)) print(bisect.bisect_right(W, L))