import heapq L = int(input()) input() e = list(map(int, input().split())) heapq.heapify(e) count = 0 while e: L -= heapq.heappop(e) if L < 0: break count += 1 print(count)