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