l=int(input()) n=int(input()) W=list(map(int,input().split())) a=sorted(W) w=0 ans=0 for i in a: w+=i if w<=l: ans+=1 print(ans)