l,n=list(int(input()) for i in range(2)) w=sorted(list(map(int, input().split()))) c=0 for i in w: l=l-i if l < 0: break c+=1 print(c)