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