import java.io.*; import java.util.*; public class Main { static int n; static int k; static long[][] dp; static int[] values; public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); n = sc.nextInt(); k = sc.nextInt(); values = new int[n]; int idx = 0; long div = 1; for (int i = 1; i <= 9; i++) { int x = sc.nextInt(); for (int j = 0; j < x; j++) { values[idx++] = i; } div *= proc(x); } dp = new long[1 << n][k]; for (long[] arr : dp) { Arrays.fill(arr, -1); } Arrays.fill(dp[0], 0); dp[0][0] = 1; System.out.println(dfw((1 << n) - 1, 0) / div); } static long proc(int x) { if (x == 0) { return 1; } else { return x * proc(x - 1); } } static long dfw(int mask, int mod) { if (dp[mask][mod] < 0) { dp[mask][mod] = 0; for (int i = 0; i < n; i++) { if ((mask & (1 << i)) == 0) { continue; } dp[mask][mod] += dfw(mask ^ (1 << i), (mod * 10 + values[i]) % k); } } return dp[mask][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(); } }