l=int(input()) n=int(input()) L=list(map(int,input().split())) L.sort() ans=0 for i in L: if 0<=l-i: ans+=1 l-=i print(ans)