from collections import defaultdict,deque import sys,heapq,bisect,math,itertools,string,queue,datetime sys.setrecursionlimit(10**8) INF = float('inf') mod = 10**9+7 eps = 10**-7 def inpl(): return list(map(int, input().split())) def inpls(): return list(input().split()) L = int(input()) N = int(input()) ww = sorted(inpl()) ww.append(INF) tmp = 0 for i,w in enumerate(ww): tmp += w if tmp > L: print(i) break