# 14個の数のどれを使ったかの状態でDP # ただし、重複ぶんを最後に割る # dp[S][k] = 状態Sで、Kで割った余りがkである場合の数 import sys readline = sys.stdin.readline N,K = map(int,readline().split()) C = list(map(int,readline().split())) X = [] for i in range(9): X += [(i + 1)] * (C[i]) dp = [[0] * K for i in range(1 << N)] dp[0][0] = 1 for status in range(1 << N): for k in range(K): # スタートする状態 if dp[status][k] == 0: continue for target in range(N): # 次に選ぶ数 if (status >> target) & 1: continue next_status = status | (1 << target) next_k = (k * 10 + X[target]) % K dp[next_status][next_k] += dp[status][k] perm = [1] * 15 for i in range(1, 15): perm[i] = perm[i - 1] * i div = 1 for c in C: if c > 1: div *= perm[c] print(dp[-1][0] // div)