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) popcount = [0] * 200000 for i in range(1, 200000): popcount[i] = popcount[i // 2] + i % 2 fact = [1] for i in range(1, n + 1): fact.append(fact[-1] * i) DP = [[0] * k for _ in range(1 << n)] DP[0][0] = 1 for bit in range(1 << n): digit = popcount[bit] for i in range(k): for j in range(n): if (bit >> j) & 1: continue num = pow(10, digit) * L[j] % k 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) if __name__ == '__main__': main()