L = int(input()) N = int(input()) W = sorted(list(map(int, input().split()))) for i in range(N): if sum(W[:i+1]) > L: exit(print(i)) print(N)