L=int(input()) input() W=sorted(map(int,input().split())) t=a=0 while t<=L: t+=W[a] a+=1 print(a-1)