#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: L-=heappop(W) if L < 0: break cnt+=1 print cnt