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: break else: a+=x b+=1 print(b)