from itertools import takewhile l = int(input()) input() s = list(sorted(map(int, input().split()))) for i in range(1, len(s)): s[i] += s[i - 1] print(len(list(takewhile(lambda x: x <= l, s))))