from collections import deque L = int(input()) N = int(input()) w = deque(sorted(map(int, input().split(" ")))) s = 0 while s <= L: s += w.popleft() else: print(N - len(w) - 1)