L= int(input()) N= int(input()) pa = [int(x) for x in input().split()] pa.sort() sum=0 for i in range(N): sum = sum+pa[i] if(sum>L): break print(i)