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