a=int(input()) b=input() c=list(map(int,input().split())) c.sort() count=0 while a-c[count]>=0 and count<=len(c): a-=c[count] count+=1 print(count)