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