l=int(input()) n=int(input()) w=list(map(int,input().split())) w.sort() sum=0 count=0 for i in range(n): sum+=w[i] if sum<=l: count+=1 print(count)