l=int(input()) n=int(input()) a=list(map(int,input().split())) a.sort() ans=0 for x in a: l-=x if l>=0: ans+=1 print(ans)