L = int(input()) N = int(input()) W = list(map(int , input().split())) W.sort() for itr in range(N): if L-W[itr] < 0: print(itr) break else : L = L - W[itr]