import sys from collections import defaultdict def main(): N, K = map(int, sys.stdin.readline().split()) c = list(map(int, sys.stdin.readline().split())) # Initial state: remainder 0, counts all 0, ways = 1 dp = defaultdict(int) initial_counts = tuple([0]*9) dp[(0, initial_counts)] = 1 for pos in range(N): next_dp = defaultdict(int) for (rem, counts), ways in dp.items(): for d in range(9): if counts[d] < c[d]: new_counts = list(counts) new_counts[d] += 1 new_counts = tuple(new_counts) new_rem = (rem * 10 + (d + 1)) % K next_dp[(new_rem, new_counts)] += ways dp = next_dp total = 0 for (rem, counts), ways in dp.items(): if rem == 0: total += ways print(total) if __name__ == '__main__': main()