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.*;
import java.util.*;

public class C implements Runnable{
	public static void main (String[] args) {new Thread(null, new C(), "_cf", 1 << 28).start();}

	int[] nums;
	int n, m;
	long[][] dp;
	
	public void run() {
		FastScanner fs = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);

		String str = fs.next();
		nums = new int[str.length()];
		for(int i = 0; i < str.length(); i++) {
			nums[i] = str.charAt(i) - '0';
		}
		
		n = str.length();
		m = fs.nextInt();
		
		dp = new long[m][1 << n];
		for(int i = 0; i < m; i++)
			Arrays.fill(dp[i], -1);
		
		out.println(go(0, 0));
		
		out.close();
	}
	
	long go (int rem, int mask) {
		if(mask == (1 << n)-1) {
//			System.out.println("Finished with rem = " + rem);
			if(rem == 0)
				return 1L;
			return 0L;
		}
		if(dp[rem][mask] != -1) return dp[rem][mask];
//		System.out.println("At " + rem + " " + Integer.toBinaryString(mask));
		long res = 0;
		boolean[] done = new boolean[10];
		for(int i = 0; i < n; i++) {
			int on = mask & (1 << i);
			if(on != 0) continue;
			if(Integer.bitCount(mask) == 0 && nums[i] == 0) continue; //leading zeros
			if(done[nums[i]]) continue;
			done[nums[i]] = true;
			int nrem = (rem*10 + nums[i]) % m;
			res += go(nrem, mask | (1 << i));
		}
		return dp[rem][mask] = res;
	}
	
	void sort (int[] a) {
		int n = a.length;
		for(int i = 0; i < 1000; i++) {
			Random r = new Random();
			int x = r.nextInt(n), y = r.nextInt(n);
			int temp = a[x];
			a[x] = a[y];
			a[y] = temp;
		}
		Arrays.sort(a);
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;
		public FastScanner() {
			try	{
				br = new BufferedReader(new InputStreamReader(System.in));
//				br = new BufferedReader(new FileReader("cases.in"));
				st = new StringTokenizer("");
			} catch (Exception e){e.printStackTrace();}
		}
		public String next() {
			if (st.hasMoreTokens())	return st.nextToken();
			try {st = new StringTokenizer(br.readLine());}
			catch (Exception e) {e.printStackTrace();}
			return st.nextToken();
		}
		public int nextInt() {return Integer.parseInt(next());}
		public long nextLong() {return Long.parseLong(next());}
		public double nextDouble() {return Double.parseDouble(next());}

		public String nextLine() {
			String line = "";
			try {line = br.readLine();}
			catch (Exception e) {e.printStackTrace();}
			return line;
		}
		public Integer[] nextIntegerArray(int n) {
			Integer[] a = new Integer[n];
			for(int i = 0; i < n; i++) a[i] = nextInt();
			return a;
		}
		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for(int i = 0; i < n; i++) a[i] = nextInt();
			return a;
		}
		public char[] nextCharArray() {return nextLine().toCharArray();}
	}

}