from collections import defaultdict n, k = map(int, input().split()) c = list(map(int, input().split())) original = tuple(c) dp = defaultdict(int) initial_remainder = 0 dp[(initial_remainder, original)] = 1 for _ in range(n): new_dp = defaultdict(int) for (rem, counts), cnt in dp.items(): for i in range(9): if counts[i] == 0: continue digit = i + 1 new_rem = (rem * 10 + digit) % k new_counts = list(counts) new_counts[i] -= 1 new_counts_tuple = tuple(new_counts) new_dp[(new_rem, new_counts_tuple)] += cnt dp = new_dp all_zero = tuple([0] * 9) print(dp.get((0, all_zero), 0))