from collections import defaultdict n, k = map(int, input().split()) c = list(map(int, input().split())) # Convert c to a tuple for use as a key in the DP dictionary c_tuple = tuple(c) # Initialize DP with the initial state: no digits used, remainder 0 dp = defaultdict(int) initial_used = tuple([0] * 9) dp[(initial_used, 0)] = 1 for _ in range(n): next_dp = defaultdict(int) for (used, rem), cnt in dp.items(): for d in range(9): if used[d] < c[d]: new_used = list(used) new_used[d] += 1 new_used_tuple = tuple(new_used) new_rem = (rem * 10 + (d + 1)) % k next_dp[(new_used_tuple, new_rem)] += cnt dp = next_dp # The answer is the count of states where all digits are used and remainder is 0 answer = dp.get((c_tuple, 0), 0) print(answer)