l = int(input()) n = int(input()) w = list(map(int,input().split())) w.sort() c=0 for i in w: if l > 0: l -= i c +=1 else: break if l >= 0: print(c) else: print(c-1)