l = int(input()) n = int(input()) wi = list(map(int,input().split())) wi.sort() for i in range(n): l -= wi[i] if l<0: print(i) quit() print(n)