l = int(input()) n = int(input()) w = list(map(int,input().split())) w.sort() answer = 0 for i in range(n): if l >= sum(w[0:i]): answer = answer + 1 else: break print(w) print(answer)