# import pypyjit # pypyjit.set_param('max_unroll_recursion=-1') from collections import * from functools import * from itertools import * from heapq import * import sys,math input = sys.stdin.readline L = int(input()) N = int(input()) W = list(map(int,input().split())) W.sort() res = 0 cnt = 0 W = deque(W) while W: w = W.popleft() if res+w<=L: res += w cnt += 1 else: break print(cnt)