max_num=int(input()) input() a=[int(i) for i in input().split()] a.sort() count=0 while max_num>0: max_num-=a[count] count+=1 print(count-1)