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()) w = sorted(list(map(int, read().split()))) for i in range(n): if sum(w[:i + 1]) > l: print(i) exit() print(n)