l=int(input()) n=int(input()) w=list(map(int,input().split())) w.sort() a=0 b=0 for x in w: if a+x >l: print(b) break else: a+=x b+=1