from collections import deque L = int(input()) N = int(input()) """if N == 1: w = deque([int(input())]) else: """ w = deque(sorted(map(int, input().split(" ")))) s = 0 while s <= L: try: s += w.popleft() except IndexError: s.append(0) break print(N - len(w) - 1)