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

public class cf401D {

    static BufferedReader br;
    static Scanner sc;
    static PrintWriter out;

    public static void initA() {
        try {
            br = new BufferedReader(new InputStreamReader(System.in));
            sc = new Scanner(System.in);
            out = new PrintWriter(System.out);
        } catch (Exception e) {
        }
    }

    static boolean next_permutation(Integer[] p) {
        for (int a = p.length - 2; a >= 0; --a) {
            if (p[a] < p[a + 1]) {
                for (int b = p.length - 1;; --b) {
                    if (p[b] > p[a]) {
                        int t = p[a];
                        p[a] = p[b];
                        p[b] = t;
                        for (++a, b = p.length - 1; a < b; ++a, --b) {
                            t = p[a];
                            p[a] = p[b];
                            p[b] = t;
                        }
                        return true;
                    }
                }
            }
        }
        return false;
    }

    public static String getString() {
        try {
            return br.readLine();
        } catch (Exception e) {
        }
        return "";
    }

    public static Integer getInt() {
        try {
            return Integer.parseInt(br.readLine());
        } catch (Exception e) {
        }
        return 0;
    }

    public static Integer[] getIntArr() {
        try {
            StringTokenizer temp = new StringTokenizer(br.readLine());
            int n = temp.countTokens();
            Integer temp2[] = new Integer[n];
            for (int i = 0; i < n; i++) {
                temp2[i] = Integer.parseInt(temp.nextToken());
            }
            return temp2;
        } catch (Exception e) {
        }
        return null;
    }

    public static Long[] getLongArr() {
        try {
            StringTokenizer temp = new StringTokenizer(br.readLine());
            int n = temp.countTokens();
            Long temp2[] = new Long[n];
            for (int i = 0; i < n; i++) {
                temp2[i] = Long.parseLong(temp.nextToken());
            }
            return temp2;
        } catch (Exception e) {
        }
        return null;
    }

    public static String[] getStringArr() {
        try {
            StringTokenizer temp = new StringTokenizer(br.readLine());
            int n = temp.countTokens();
            String temp2[] = new String[n];
            for (int i = 0; i < n; i++) {
                temp2[i] = (temp.nextToken());
            }
            return temp2;
        } catch (Exception e) {
        }
        return null;
    }

    public static void print(Object a) {
        System.out.println(a);
    }

    public static void print(String s, Object... a) {
        System.out.printf(s, a);
    }

    public static int nextInt() {
        return sc.nextInt();
    }

    public static double nextDouble() {
        return sc.nextDouble();
    }

    public static void main(String[] ar) {
        initA();
        cf401D c = new cf401D();
        c.solve();
        out.flush();
    }
    int inp[] = new int[25];
    int n;
    short moder;

    void solve() {
        String in[] = getStringArr();
        char cb[] = in[0].toCharArray();
        n = cb.length;
        int ct[] = new int[10];
        for (int i = 0; i < n; i++) {
            inp[i] = cb[i] - '0';
            ct[inp[i]]++;
        }


        moder = Short.valueOf(in[1]);

        //print(100 * 100 * (1<<18) * 20);

        int end = (1 << (n));
        //print(end+" "+Integer.toString(end,2));
        long bef[][] = new long[end][100];
        bef[0][0] = 1;
        int bit[] = new int[end];
        for (int i = 0; i < end; i++) {
            int num =  0;
            int tv = i;
            while(tv > 0){
                if(tv%2==1){
                    num++;
                }
                tv/=2;
            }
            
            bit[i] = num;
        }
        for (int i = 1; i <= n; i++) {

            for (int k = 0; k < end; k++) {
                if(bit[k]!=i-1)continue;
                for (int j = 0; j < moder; j++) {

                    if (bef[k][j] > 0) {
                        for (int l = 0; l < n; l++) {
                            if ((k & (1 << l)) == 0) {
                                if (i == 1 && inp[l] == 0) {
                                    continue;
                                }
                                int nv = (j * 10 + inp[l]) % moder;
                                int nb = k | (1 << l);
                                //print("SEBELUM ERROR" + nv+" "+nb);
                                bef[nb][nv] += bef[k][j];
                                //print(nv + " " + Integer.toString(nb, 2) + " = " + bef[nb][nv]);
                            }
                        }
                    }
                }
            }


        }
        long ou = bef[end - 1][0];
        //print(ou);
        for (int i = 0; i < 10; i++) {
            ou /= fact(ct[i]);
        }
        print(ou);


    }

    long fact(int n) {
        if (n <= 1) {
            return 1;
        }
        return fact(n - 1) * n;
    }
}