L=int(input()) N=int(input()) W=sorted(list(map(int,input().split()))) ans=0 cnt=0 for i in W: if cnt+i>L: break cnt+=i ans+=1 print(ans)