block=input() num=input() block_num=sorted(map(int,input().split())) cut=0 for i in range(num): block-=block_num[i] if block<0: break cut+=1 print(cut)