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.BufferedOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Random;
import java.util.function.Consumer;

public class Solution {

    public static void main(String[] args) {
        try (PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out))) {
            _Scanner sc = new _Scanner(System.in);

            // 17:34-

            long n = sc.nextLong();
            int m = sc.nextInt();

            int len = String.valueOf(n).length();

            long[][] dp = new long[1 << len][m];
            dp[0][0] = 1;

            long[] pows = new long[18];
            pows[0] = 1;
            for (int i = 1; i < pows.length; i++) pows[i] = pows[i - 1] * 10;

            long[] fac = new long[18];
            fac[0] = 1;
            for (int i = 1; i < fac.length; i++) fac[i] = i * fac[i - 1];

            int[] freq = new int[10];
            for (long t = n; t > 0; t /= 10) freq[(int) (t % 10)]++;
            long div = 1;
            for (int num : freq) div *= fac[num];

            for (int k = 0; k < len; k++) {
                for (int j = 0; j < len; j++) {
                    int d = (int) (n / pows[j] % 10);
                    int mod = (int) (d * pows[k] % m);

                    if (k == len - 1 && d == 0) continue;

                    int finalJ = j;
                    doit(0, 0, k, len, 0, num -> {
                        if (((1 << finalJ) & num) == 0) {
                            for (int i = 0; i < m; i++) {
                                dp[num | (1 << finalJ)][(i + mod) % m] += dp[num][i];
                            }
                        }
                    });
                }
            }

            out.println(dp[(1 << len) - 1][0] / div);
        }
    }

    private static void doit(int idx, int set, int target, int len, int tmp, Consumer<Integer> consumer) {
        if (len == idx) {
            if (set == target) {
                consumer.accept(tmp);
            }
            return;
        }

        if (set < target) doit(idx + 1, set + 1, target, len, tmp | (1 << idx), consumer);
        doit(idx + 1, set, target, len, tmp, consumer);
    }



    private static void reverse(int[] vs) {
        for (int i = 0; i < vs.length / 2; i++) {
            swap(vs, i, vs.length - 1 - i);
        }
    }

    static class _Scanner {
        InputStream is;

        _Scanner(InputStream is) {
            this.is = is;
        }

        byte[] bb = new byte[1 << 15];
        int k, l;

        byte getc() {
            try {
                if (k >= l) {
                    k = 0;
                    l = is.read(bb);
                    if (l < 0) return -1;
                }
                return bb[k++];
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        byte skip() {
            byte b;
            while ((b = getc()) <= 32)
                ;
            return b;
        }

        int nextInt() {
            int n = 0;
            int sig = 1;
            for (byte b = skip(); b > 32; b = getc()) {
                if (b == '-') {
                    sig = -1;
                } else {
                    n = n * 10 + b - '0';
                }
            }
            return sig * n;
        }

        long nextLong() {
            long n = 0;
            long sig = 1;
            for (byte b = skip(); b > 32; b = getc()) {
                if (b == '-') {
                    sig = -1;
                } else {
                    n = n * 10 + b - '0';
                }
            }
            return sig * n;
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        public String next() {
            StringBuilder sb = new StringBuilder();
            for (int b = skip(); b > 32; b = getc()) {
                sb.append(((char) b));
            }
            return sb.toString();
        }
    }

    private static void shuffle(int[] ar) {
        Random rnd = new Random();
        shuffle(ar, rnd);
    }
    
    private static void shuffle(long[] ar) {
        Random rnd = new Random();
        shuffle(ar, rnd);
    }

    private static void shuffle(int[] ar, Random rnd) {
        for (int i = 0; i < ar.length; i++) {
            int j = i + rnd.nextInt(ar.length - i);
            swap(ar, i, j);
        }
    }
    
    private static void shuffle(long[] ar, Random rnd) {
        for (int i = 0; i < ar.length; i++) {
            int j = i + rnd.nextInt(ar.length - i);
            swap(ar, i, j);
        }
    }

    private static void shuffle(Object[] ar) {
        Random rnd = new Random();
        for (int i = 0; i < ar.length; i++) {
            int j = i + rnd.nextInt(ar.length - i);
            swap(ar, i, j);
        }
    }

    private static void swap(int[] ar, int i, int j) {
        int t = ar[i];
        ar[i] = ar[j];
        ar[j] = t;
    }

    private static void swap(long[] ar, int i, int j) {
        long t = ar[i];
        ar[i] = ar[j];
        ar[j] = t;
    }

    private static void swap(Object[] ar, int i, int j) {
        Object t = ar[i];
        ar[i] = ar[j];
        ar[j] = t;
    }

}
