import sys import itertools L = int(sys.stdin.readline().strip()) N = int(sys.stdin.readline().strip()) W = list(map(int,sys.stdin.readline().strip().split())) WW = sorted(W,reverse=True) if sum(WW) > L : for n in range(N) : WW.pop(0) if sum(WW) <= L : print(len(WW)) break else : print(len(WW))