width = int(input()) N = int(input()) bl = list(map(int, input().split())) bl.sort() bs = 0 if sum(bl) == width: print(len(bl)) exit() for i in range(N): if bs + bl[i] <= width: bs += bl[i] else: print(i) exit()