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