box=int(input()) n=int(input()) sbox=list(map(int,input().split())) sbox.sort() sumnum=0 for i in range(len(sbox)): sumnum+=sbox[i] if sumnum>box: print(i) break elif sumnum==box: print(i+1) break print(i+1)