L = int(input()) N = int(input()) W = sorted(list(map(int, input().split()))) c = 0 a = 0 for i in range(N): if c + W[i] <= L: c = c + W[i] a = i + 1 else: break print(a)