import sys input = sys.stdin.readline def main(): n, k = map(int, input().split()) C = list(map(int, input().split())) L = [] for i in range(9): L += [i + 1] * C[i] DP = [[0] * k for _ in range(1 << n)] DP[0][0] = 1 for bit in range(1 << n): for i in range(k): if DP[bit][i] == 0: continue for j in range(n): if bit & (1 << j): continue r = (10 * i + L[j]) % k nbit = bit | (1 << j) DP[nbit][r] += DP[bit][i] ans = DP[-1][0] for i in range(9): for j in range(1, C[i] + 1): ans //= j print(ans) if __name__ == '__main__': main()