import itertools n,p=map(int,input().split()) c1=list(map(int,input().split())) c2=[] for i in range(9): c2.append([c1[i],i]) c2.sort(reverse=True) q=[1]*n for i in range(1,n): q[i]=(q[i-1]*10)%p d=set([0]) memo=[[0]*p for i in range(2**n)] memo[0][0]=1 for a in range(9): i=c2[a][1] if c1[i]==0: continue e=set() for j in d: t=[] for k in range(n): if (j>>k)&1==0: t.append(k) all=itertools.combinations(t,c1[i]) for x in all: y=j cnt=0 for k in x: cnt+=q[k] y+=2**k for k in range(p): s=(cnt*(i+1)+k)%p memo[y][s]+=memo[j][k] e.add(y) d=e.copy() print(memo[2**n-1][0])