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(1, n + 1): if sum(w[:i + 1]) > l: print(i) exit()