#coding:utf-8 from heapq import heapify,heappop L=input() N=input() W_str=raw_input().split() W=[int(i) for i in W_str] heapify(W) cnt=0 while True: if W: L-=heappop(W) if L < 0: break cnt+=1 else: break print cnt