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