l=input() n=input() w=sorted(map(int,raw_input().split())) print len([i for i in range(n)if sum(w[:i+1])<=l])