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.InputStreamReader;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.PrintStream;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Reader;
import java.io.Writer;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Nipuna Samarasekara
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		FastScanner in = new FastScanner(inputStream);
		FastPrinter out = new FastPrinter(outputStream);
		TaskD solver = new TaskD();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskD {
   /////////////////////////////////////////////////////////////
    public void solve(int testNumber, FastScanner in, FastPrinter out) {
    long n=in.nextLong();
        int m=in.nextInt();
        String S=""+n;
        int len=S.length();
     long[][] dp= new long[(1<<len)+1][m];
      dp[0][0]=1;
      int[]  pow2= new int[30];
        pow2[0]=1;
        for (int i = 1; i < 30; i++) {
            pow2[i]=2*pow2[i-1];
        }
     long[] pow10= new long[30];
        pow10[0]=1;
        for (int i = 1; i < 30; i++) {
            pow10[i]=(pow10[i-1]*10)%m;
        }
        for (int i = 0; i < len; i++) {
            int cur=(int)S.charAt(i)-(int)'0';
            for (int j = 0; j <= (1<<len) ; j++) {
//                int[] dd=new int[len];
//                for (int l = 0; l < len; l++) {
//
//                    if((j&pow2[l])>0)
//                       dd[l]=1 ;
//                }

                if(Integer.bitCount(j)==i)
                for (int k = 0; k < m; k++) {
                   if(dp[j][k]!=0){
                       for (int l = 0; l < len; l++) {
                         if(cur==0&&l==0)continue;
                           if((j&pow2[l])==0) {
                            int newj=(j|pow2[l]),newk= (int)((k+pow10[len-1-l]*cur));
                               while(newk>=m)newk-=m;
                            dp[newj][newk]+=dp[j][k];

                           }
                       }



                   }

                }
            }
        }

    long ans=  dp[(1<<len)-1][0];
      //  System.out.println(ans);
        int[] aa= new int[10];
        for (int i = 0; i < len; i++) {
            aa[(int)S.charAt(i)-(int)'0']++;
        }
      long[] fact= new long[20];
        fact[0]=1;
        for (int i = 1; i < 20; i++) {
            fact[i]=i*fact[i-1];
        }
        for (int i = 0; i < 10; i++) {
            if(aa[i]>1)ans/=fact[aa[i]];
        }
     //   deb(dp[31]);
        out.println(ans);
      //  deb(dp);
    }
}

class FastScanner extends BufferedReader {

    public FastScanner(InputStream is) {
        super(new InputStreamReader(is));
    }

    public int read() {
        try {
            int ret = super.read();
//            if (isEOF && ret < 0) {
//                throw new InputMismatchException();
//            }
//            isEOF = ret == -1;
            return ret;
        } catch (IOException e) {
            throw new InputMismatchException();
        }
    }

    public String next() {
        StringBuilder sb = new StringBuilder();
        int c = read();
        while (isWhiteSpace(c)) {
            c = read();
        }
        if (c < 0) {
            return null;
        }
        while (c >= 0 && !isWhiteSpace(c)) {
            sb.appendCodePoint(c);
            c = read();
        }
        return sb.toString();
    }

    static boolean isWhiteSpace(int c) {
        return c >= 0 && c <= 32;
    }

    public int nextInt() {
        int c = read();
        while (isWhiteSpace(c)) {
            c = read();
        }
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        int ret = 0;
        while (c >= 0 && !isWhiteSpace(c)) {
            if (c < '0' || c > '9') {
                throw new NumberFormatException("digit expected " + (char) c
                        + " found");
            }
            ret = ret * 10 + c - '0';
            c = read();
        }
        return ret * sgn;
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public String readLine() {
        try {
            return super.readLine();
        } catch (IOException e) {
            return null;
        }
    }

    }

class FastPrinter extends PrintWriter {

    public FastPrinter(OutputStream out) {
        super(out);
    }

    public FastPrinter(Writer out) {
        super(out);
    }


}

