L=int(input()) N=int(input()) W = input().split() W.sort(key=int) for i in range(N): if L>=(W[i]): L-=(W[i]) else: print(i) break