L=int(input()) input() W=sorted(map(int,input().split())) t=a=0 for i in W: t+=i if t>L:break a+=1 print(a)