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.IOException;
	import java.io.InputStream;
	import java.io.PrintWriter;
	import java.util.Arrays;
	import java.util.InputMismatchException;
	
	public class CF {
		static int mod, N; 
		static int[] array;
		static long[][] memo;
		static int[] powpow;
		static int[][][] magic;
		public static void main(String[] args) {
			FasterScanner sc = new FasterScanner();
			PrintWriter out = new PrintWriter(System.out);
			char[] str = sc.next().toCharArray();
			int pow = 1;
			mod = sc.nextInt();
			magic = new int[20][10][mod];
			for(int a=0;a<20;a++){
				for(int b=0;b<10;b++)
					for(int c=0;c<mod;c++)
						magic[a][b][c]=(pow*b+c)%mod;
				pow*=10;
				pow%=mod;
			}
			N = str.length;
			array = new int[N];
			int[] freq = new int[10];
			for(int a=0;a<N;a++)
				freq[array[a]=str[a]-'0']++;
			Arrays.sort(array);
			memo = new long[mod][1<<N];
			for(int a=0;a<mod;a++)Arrays.fill(memo[a],-1);
			long ways = DP(0,0);
			long[] factorial = new long[20];
			factorial[0]=1;
			long bad = 1;
			for(int a=1;a<20;a++)
				factorial[a]=factorial[a-1]*a;
		//	for(int a=0;a<10;a++)
		//		bad*=factorial[freq[a]];
			out.println(ways/bad);
			out.close();
		}
		
	
		private static long DP(int mask, int remain) {
			if(memo[remain][mask]!=-1)return memo[remain][mask];
			if(mask==(1<<N)-1)
				return memo[remain][mask]=(remain==0?1L:0L);
			long ans = 0;
			for(int a=0;a<N;a++){
				if(((mask>>a)&1)==0){
					if(Integer.bitCount(mask)==0){
						if(array[a]==0)continue;
					}
					if(a>0&&(mask>>(a-1)&1)==0&&array[a]==array[a-1])continue;
					ans+=DP(mask+(1<<a),(magic[N-Integer.bitCount(mask)-1][array[a]][remain]));	
				//	ans+=DP(mask+(1<<a),(powpow[N-Integer.bitCount(mask)-1]*array[a]+remain)%mod);
				}
			}
			return memo[remain][mask]=ans;
		}
	
		static boolean nextperm(int[] vals) {
			int N = vals.length;
			int K = -1;
			for(int a=N-2;a>=0;a--){
				if(vals[a]<vals[a+1]){
					K=a;
					break;
				}
			}
			if(K==-1)return false;
			for(int a=N-1;a>K;a--){
				if(vals[K]<vals[a]){
					swap(K,a,vals);
					break;
				}
			}
			int L = K+1;
			int R = N-1;
			while(L<R){
				swap(L,R,vals);
				L++;
				R--;
			}
			return true;
		}
	
		public static void swap(int i, int j, int[] v) {
			int t = v[i];
			v[i] = v[j];
			v[j] = t;
		}
	
		static class FasterScanner {
			private InputStream stream;
			private byte[] buf = new byte[1024];
			private int curChar;
			private int numChars;
	
			public FasterScanner() {
				stream = System.in;
				// stream = new FileInputStream(new File("dec.in"));
	
			}
	
			int read() {
				if (numChars == -1)
					throw new InputMismatchException();
				if (curChar >= numChars) {
					curChar = 0;
					try {
						numChars = stream.read(buf);
					} catch (IOException e) {
						throw new InputMismatchException();
					}
					if (numChars <= 0)
						return -1;
				}
				return buf[curChar++];
			}
	
			boolean isSpaceChar(int c) {
				return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
			}
	
			boolean isEndline(int c) {
				return c == '\n' || c == '\r' || c == -1;
			}
	
			int nextInt() {
				return Integer.parseInt(next());
			}
	
			long nextLong() {
				return Long.parseLong(next());
			}
	
			double nextDouble() {
				return Double.parseDouble(next());
			}
	
			String next() {
				int c = read();
				while (isSpaceChar(c))
					c = read();
				StringBuilder res = new StringBuilder();
				do {
					res.appendCodePoint(c);
					c = read();
				} while (!isSpaceChar(c));
				return res.toString();
			}
	
			String nextLine() {
				int c = read();
				while (isEndline(c))
					c = read();
				StringBuilder res = new StringBuilder();
				do {
					res.appendCodePoint(c);
					c = read();
				} while (!isEndline(c));
				return res.toString();
			}
	
		}
	
	}