def main(): n, k = map(int, input().split()) C = list(map(int, input().split())) L = [] for i in range(9): for num in range(C[i]): L.append(i + 1) fact = [1] for i in range(1, n + 1): fact.append(fact[-1] * i) DP = [[0 for _ in range(k)] for _ in range(1 << n)] DP[0][0] = 1 for bit in range(1 << n): seen = set() digit = 0 for i in range(n): if (bit >> i) & 1: seen.add(i) digit += 1 for i in range(k): if DP[bit][i] != 0: for j in range(n): if j in seen: continue num = pow(10, digit) * L[j] r = (i + num) % k DP[bit | (1 << j)][r] += DP[bit][i] ans = DP[-1][0] for i in range(9): ans //= fact[C[i]] print(ans) main()