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.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Abood2C {
	static int N;
	static long memo[][];
	static int MOD;
	static String s;
	static long solve(int i, int m) {
		
		if(i == 0 && m == 0)
			return 1;
		if(i == 0)
			return 0;
		if(memo[i][m] != -1)
			return memo[i][m];

		long ans = 0;
		int p = 1;
		int c = 0;
		for (int j = 0; j < N; j++) {
			if((i & (1 << j)) == 0)
				c++;
		}
		for (int j = 0; j < c; j++) {
			p *= 10;
			p %= MOD;
		}
		for (int j = 0; j < N; j++) {
			if((i & (1 << j)) == 0 || s.charAt(j) == '0' && (i ^ (1 << j)) == 0)
				continue;
			boolean v = false;
			for (int j2 = 0; j2 < j; j2++)
				if((i & (1 << j2)) != 0 && s.charAt(j) == s.charAt(j2)) {
					v = true;
					continue;
				}
			
			if(v)
				continue;
			
			ans += solve((i ^ (1 << j)), ((s.charAt(j) - '0') * p + m) % MOD);
		}
		return memo[i][m] = ans;
	}

	public static void main(String[] args) throws Exception{
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		s = sc.next();
		N = s.length();
		MOD = sc.nextInt();

		
		memo = new long [(1 << N)][MOD + 1];
		for (int i = 0; i < memo.length; i++)

			Arrays.fill(memo[i], -1);

		out.println(solve(memo.length - 1, 0));

		out.flush();
		out.close();
	}

	static class Scanner 
	{
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream System){	br = new BufferedReader(new InputStreamReader(System));}
		public String next() throws IOException 
		{
			while (st == null || !st.hasMoreTokens()) 
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public String nextLine()throws IOException{return br.readLine();}
		public int nextInt() throws IOException {return Integer.parseInt(next());}
		public double nextDouble() throws IOException {return Double.parseDouble(next());}
		public char nextChar()throws IOException{return next().charAt(0);}
		public Long nextLong()throws IOException{return Long.parseLong(next());}
		public boolean ready() throws IOException{return br.ready();}
		public void waitForInput(){for(long i = 0; i < 3e9; i++);}
	}
}