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