Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m.

Number x is considered close to number n modulo m, if:

  * it can be obtained by rearranging the digits of number n, 
  * it doesn't have any leading zeroes, 
  * the remainder after dividing number x by m equals 0. 



Roman is a good mathematician, but the number of such numbers is too huge for him. So he asks you to help him.

Input

The first line contains two integers: n (1 ≤ n < 1018) and m (1 ≤ m ≤ 100).

Output

In a single line print a single integer — the number of numbers close to number n modulo m.

Examples

Input

104 2


Output

3


Input

223 4


Output

1


Input

7067678 8


Output

47

Note

In the first sample the required numbers are: 104, 140, 410.

In the second sample the required number is 232.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.concurrent.PriorityBlockingQueue;

public class aa {

	public static class node implements Comparable<node> {
		int x;
		int y;

		node(int x, int y) {
			this.x = x;
			this.y = y;
		}

		@Override
		public int compareTo(node o) {
			if (o.x < x)
				return 1;
			else if (o.x > x)
				return -1;
			else if (o.y < y)
				return 1;
			else
				return -1;
		}
	}

	public static int mod;
	public static String num;

	public static long dp[][];
	public static int a[];
	public static int n;

	public static long getFact() {
		int a[] = new int[10];
		for (int i = 0; i < num.length(); i++) {
			a[num.charAt(i) - 48]++;
		}
		long fact = 1;
		for (int i = 0; i < 10; i++) {
			if (a[i] != 0)
				fact *= fact(a[i]);
		}
		return fact;
	}

	public static long fact(int n) {
		long ans = 1;
		for (int i = 1; i <= n; i++) {
			ans *= i;
		}
		return ans;
	}

	public static long f;

	public static long solve(int mask, int number, int count, int last) {

		if (mask == (1 << n) - 1) {
			if (number == 0)
				return 1;
			return 0;

		}
		if (dp[mask][number] != -1)
			return dp[mask][number];
		long a1 = 0;
		for (int i = 0; i < n; i++) {

			// if (a[i] != last) {
			if (count != 0 || a[i] != 0) {
				if(i>0&&(mask&(1<<(i-1)))==0&&a[i-1]==a[i])
					continue;
				if ((mask & (1 << i)) == 0) {
					a1 += solve(mask | (1 << i), (number * 10 + a[i]) % mod,
							count + 1, a[i]);
					
				}
			}
			// }

		}
		dp[mask][number] = a1;
		return a1;

	}

	public static void main(String[] args) throws IOException {

		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
		StringBuilder q = new StringBuilder();
		String y[] = in.readLine().trim().split(" ");
		num = y[0];
		mod = Integer.parseInt(y[1]);
		n = num.length();
		a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = num.charAt(i) - 48;
		}
		Arrays.sort(a);

		dp = new long[1 << n + 1][mod];
		for (int i = 0; i < (1 << n + 1); i++) {
			for (int j = 0; j < mod; j++) {
				dp[i][j] = -1;
			}
		}
		f = getFact();

		// System.out.println(t);
		// System.out.println(f);
		out.println((long) solve(0, 0, 0, 0));

		out.print(q);
		out.close();

	}
}