L = int(input()) N = int(input()) w = sorted(map(int, input().split(" ")), reverse = True) s = 0 while True: try: s += w.pop() if s >= L: break except IndexError: break print(N - len(w) - (s > L) * 1)