L = int(input()) N = int(input()) W = sorted(map(int, input().split())) c = 0 for w in W: L-=w if L>=0: c+=1 print(c)