#!/usr/bin/env python3 # from typing import * import sys import io import math import collections import decimal import itertools import bisect import heapq def input(): return sys.stdin.readline()[:-1] # sys.setrecursionlimit(1000000) # _INPUT = """3 2 # 1 2 0 0 0 0 0 0 0 # """ # sys.stdin = io.StringIO(_INPUT) INF = 10**10 def get_count(mask, i): for j in range(i): mask //= (C[j]+1) n = mask % (C[i]+1) return n def set_count(mask, i, n): k = 1 for j in range(i): k *= (C[j]+1) mask1 = (mask // (k * (C[i]+1)) * (C[i]+1) + n) * k + (mask % k) return mask1 N, K = map(int, input().split()) C = list(map(int, input().split())) M = 1 for i in range(9): M *= (C[i]+1) A = [] for i in range(9): A += [i+1] * C[i] dp = [[0] * K for _ in range(M)] dp[0][0] = 1 for mask in range(M): for r in range(K): if dp[mask][r] == 0: continue for i in range(9): n = get_count(mask, i) if n == C[i]: continue mask1 = set_count(mask, i, n+1) r1 = (10*r+(i+1)) % K dp[mask1][r1] += dp[mask][r] ans = dp[(M)-1][0] print(ans)