L = int(input()) input() num = i = 0 for W in sorted(map(int, input().split())): num += W if num > L: break i += 1 print(i)