L = int(input()) N = int(input()) Ws = list(map(int, input().split(' '))) Ws.sort() for i in range(len(Ws)): if sum(Ws[:i+1]) > L: print(i) break