L=int(input()) input() W=sorted(list(map(int, input().split()))) b=0 for i in W: L-=i if L<0:break b+=1 print(b)