#coding=UTF-8 #greedyかしら L=int(input()) N=int(input()) mojir=input() blocks=[] for monomoji in mojir.split(' '): blocks.append(int(monomoji)) kireiblocks=sorted(blocks) irehaba=0 ans=0 for mono in kireiblocks: irehaba=irehaba+mono if irehaba > L: break ans=ans+1 print(ans)