L = int(input()) N = int(input()) W = list(map(int, input().split())) X = sorted(W) total = 0 y = 0 for n in range(N): total += X[n] if total >= L: break y += 1 print(y)