L = int(input()) N = int(input()) W = sorted(map(int, input().split())) sum_i = 0 for i in range(N): j = sum_i + W[i] if j <= L: sum_i = j else: print(i)