L,N=map(int,input().split()) W=list(map(int,input().split())) W.sort() total=0 ans=0 for w in W: if total+w<=L: total+=w ans+=1 else: break print(ans)