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.util.Arrays;
import java.util.HashMap;
import java.util.StringTokenizer;


public class D  {
	
	static class Scanner{
		BufferedReader br=null;
		StringTokenizer tk=null;
		public Scanner(){
			br=new BufferedReader(new InputStreamReader(System.in));
		}
		public String next() throws IOException{
			while(tk==null || !tk.hasMoreTokens())
				tk=new StringTokenizer(br.readLine());
			return tk.nextToken();
		}
		public int nextInt() throws NumberFormatException, IOException{
			return Integer.valueOf(next());
		}
		public long nextLong() throws NumberFormatException, IOException{
			return Long.valueOf(next());
		}
		public double nextDouble() throws NumberFormatException, IOException{
			return Double.valueOf(next());
		}
	}
	
	static class State{
		@Override
		public int hashCode() {
			final int prime = 31;
			int result = 1;
			result = prime * result + Arrays.hashCode(a);
			result = prime * result + mod;
			return result;
		}
		@Override
		public boolean equals(Object obj) {
			if (this == obj)
				return true;
			if (obj == null)
				return false;
			if (getClass() != obj.getClass())
				return false;
			State other = (State) obj;
			if (!Arrays.equals(a, other.a))
				return false;
			if (mod != other.mod)
				return false;
			return true;
		}
		int[] a;
		int mod;
		public State(int[] b, int m){
			a = b;
			mod = m;
		}
		int getdigits(){
			int ret = 0;
			for(int i = 0; i < a.length; i++)
				ret += a[i];
			return ret;
		}
	}
	
	
	static HashMap<State, Long> dp;
	static int totaldigits;
	static int[] powmod10;
	static long N;
	static int M;
	
	
	static long dp(State s){
		if (dp.containsKey(s))
			return dp.get(s);
		int[] array = s.a;
		int mod = s.mod;
		int faltan  = s.getdigits();
		if (faltan == 0){
			return (mod == 0)?1L:0L;
		}
		long ret = 0;
		for(int i = 0; i < array.length; i++){
			if(array[i] == 0)
				continue;
			if (faltan == totaldigits && i == 0)
				continue;
			int nmod = (powmod10[faltan - 1] * i) % M;
			nmod = (mod + nmod) % M;
			array[i]--;
			State ns = new State(array, nmod);
			ret += dp(ns);
			array[i]++;
		}
		dp.put(s, ret);
		return ret;
	}
	
	public static void main(String args[]) throws NumberFormatException, IOException{
		Scanner sc = new Scanner();
		N = sc.nextLong();
		M = sc.nextInt();
		totaldigits = (N+"").length();
		powmod10 = new int[20];
		powmod10[0] = 1 % M;
		for(int i = 1; i < 20; i++)
			powmod10[i] = (powmod10[i - 1] * 10) % M;
		int[] array = new int[10];
		Arrays.fill(array, 0);
		String cad = N + "";
		for(int i = 0; i < cad.length(); i++)
			array[cad.charAt(i) - '0']++;
		State s = new State(array, 0);
		dp = new HashMap<State, Long>();
		System.out.println(dp(s));
	}

}
