import java.io.*; import java.util.*; public class Main { static int k; static HashMap> dp = new HashMap<>(); static long[] base = new long[11]; public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); k = sc.nextInt(); base[0] = 1; for (int i = 1; i <= 10; i++) { base[i] = base[i - 1] * 10; } long mask = 0; for (int i = 0; i < 9; i++) { mask += sc.nextInt() * base[i]; } System.out.println(dfw(mask, 0)); } static long dfw(long mask, int mod) { if (mask == 0) { if (mod == 0) { return 1; } else { return 0; } } if (!dp.containsKey(mask)) { dp.put(mask, new HashMap<>()); } if (!dp.get(mask).containsKey(mod)) { long ans = 0; for (int i = 0; i < 10; i++) { if (mask % base[i + 1] / base[i] == 0) { continue; } ans += dfw(mask - base[i], (mod * 10 + i + 1) % k); } dp.get(mask).put(mod, ans); } return dp.get(mask).get(mod); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }