#!/usr/bin/python3.8 N,K=map(int,input().split()) C=list(map(int,input().split())) nums=[] from collections import defaultdict for i in range(1,10): nums+=[i]*C[i-1] dp=[defaultdict(int) for i in range(2**N)] dp[0][0]+=1 #########bit library ######### def popcount(a): return bin(a).count('1') #Sの部分集合の列挙、降順 def subset(S): T=S while T: T=S&(T-1) yield T #N桁の二進数のうち丁度Kbitだけ立っている数の列挙 #昇順 def Kbits(N,K): if N> 1 | y #S&v = v を満たすvの列挙、昇順 def flags(S): while S: v=S&(-S) S^=v yield v def flag_inds(S): while S: v=S&(-S) S^=v yield v.bit_length()-1 #1つだけビットが立っていないものの列挙、降順 def childs(S): tmp=S while tmp: v=tmp&(-tmp) tmp^=v yield S^v,v.bit_length()-1 def post(S): assert S>0 v=S&(-S) return S^v,v.bit_length()-1 #########bit library end######### for S in range(1,2**N): for P,j in childs(S): num=nums[j] for k,v in dp[P].items(): dp[S][(10*k+num)%K]+=v print(dp[-1][0])