l=int(input()) n=int(input()) w=list(map(float,input().split())) w.sort() remain = l counter=0 for wi in w: if remain>=0: remain = remain-wi counter +=1 elif remain<0: counter -=1 break print(counter)