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