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