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