import sys import math from collections import defaultdict def main(): N, K = map(int, sys.stdin.readline().split()) c = list(map(int, sys.stdin.readline().split())) product_fact = 1 for count in c: product_fact *= math.factorial(count) initial_counts = tuple(c) dp = defaultdict(int) dp[(initial_counts, 0)] = 1 for _ in range(N): next_dp = defaultdict(int) for (counts, rem), cnt in dp.items(): for i in range(9): if counts[i] > 0: new_counts = list(counts) new_counts[i] -= 1 new_counts_tuple = tuple(new_counts) digit = i + 1 new_rem = (rem * 10 + digit) % K next_dp[(new_counts_tuple, new_rem)] += cnt * counts[i] dp = next_dp sum_answer = 0 for (counts, rem), cnt in dp.items(): if all(x == 0 for x in counts) and rem == 0: sum_answer += cnt print(sum_answer // product_fact) if __name__ == "__main__": main()