l=int(input()) input() w=list(map(int,input().split())) w.sort() cnt=0 for i in w: if l>=i: cnt+=1 l-=i else: break print(cnt)