import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 7) l = int(readline()) n = int(readline()) a = sorted(list(map(int, read().split()))) for i in range(n): if l < sum(a[:i + 1]): print(i) exit() print(n)