""" """ import sys from sys import stdin import math N,K = map(int,stdin.readline().split()) mod = K c = [0] + list(map(int,stdin.readline().split())) C = [] for i in range(10): for j in range(c[i]): C.append(i) dp = [ {} for i in range(2**N) ] dic = dp dp[0][0] = 1 for i in range(2**N): popcnt = 0 for j in range(N): if 2**j & i > 0: popcnt += 1 npow = pow(10,popcnt,mod) for j in range(N): if i & (2**j) == 0: nexv = i | (2**j) for nm in dic[i]: nexm = (nm + C[j] * npow) % mod if nexm not in dp[nexv]: dp[nexv][nexm] = 0 dp[nexv][nexm] += dp[i][nm] if 0 not in dp[2**N-1]: ans = 0 else: ans = dp[2**N-1][0] for j in range(10): ans //= math.factorial(c[j]) print (ans)