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.util.*;

public class Main {

    static StringBuilder st = new StringBuilder();
    static int n, m, a[];
    static long[][][][][][][][][][][][] memo;// idx , taken , mod , zero , one , two , three , four , five , six , seven , eight , nine

    static int mult(int a , int b , int MOD) {return (int)((1l * a * b) % MOD) ; }
    static int add(int a , int b , int MOD) {return (a+b) % MOD;}


    static long dp(int idx, int mod, int[] cnt) {

        if (idx == n && mod == 0)
            return 1;

        if (idx == n)
            return 0;

        if (check(idx, mod, cnt))
            return get(idx, mod, cnt);

        long ans = 0 ;
        for (int i = 0; i < 10; i++) {
            if (cnt[i] > 0) {
                int[] newCnt = cnt.clone();
                newCnt[i]--;
                if (i == 0 && idx == 0) continue;
                ans += dp(idx + 1, add(i, mult(10, mod, m), m), newCnt );
            }
        }

        return set(idx, mod, cnt, ans);

    }

    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        PrintWriter out = new PrintWriter(System.out);

        char[] c = sc.next().toCharArray();
        n = c.length;
        m = sc.nextInt();
        init(n, m, c);
        int [] cnt = new int [10];
        for(int x : a)
            cnt[x]++;

        out.println(dp(0, m, cnt));

        out.flush();
        out.close();

    }

    static class Scanner {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st;

        Scanner() {
        }

        Scanner(String path) throws Exception {
            br = new BufferedReader(new FileReader(path));
        }

        String next() throws Exception {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        int nextInt() throws Exception {
            return Integer.parseInt(next());
        }

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

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

    static void shuffle(int[] a) {
        int n = a.length;
        for (int i = 0; i < n; i++) {
            int r = i + (int) (Math.random() * (n - i));
            int tmp = a[i];
            a[i] = a[r];
            a[r] = tmp;
        }
    }

    static void shuffle(char[] a) {
        int n = a.length;
        for (int i = 0; i < n; i++) {
            int r = i + (int) (Math.random() * (n - i));
            char tmp = a[i];
            a[i] = a[r];
            a[r] = tmp;
        }
    }

    static void shuffle(long[] a) {
        int n = a.length;
        for (int i = 0; i < n; i++) {
            int r = i + (int) (Math.random() * (n - i));
            long tmp = a[i];
            a[i] = a[r];
            a[r] = tmp;
        }
    }

    private static boolean oj = System.getProperty("ONLINE_JUDGE") != null;

    private static void tr(Object... o) {
        if (!oj)
            System.out.println(Arrays.deepToString(o));
    }

    static boolean check(int idx, int mod, int[] cnt) {
        return (memo[idx][cnt[0]][cnt[1]][cnt[2]][cnt[3]][cnt[4]][cnt[5]][cnt[6]][cnt[7]][cnt[8]][cnt[9]][mod] != -1);
    }

    static long get(int idx, int mod, int[] cnt) {
        return memo[idx][cnt[0]][cnt[1]][cnt[2]][cnt[3]][cnt[4]][cnt[5]][cnt[6]][cnt[7]][cnt[8]][cnt[9]][mod];
    }

    static long set(int idx, int mod, int[] cnt, long val) {
        return memo[idx][cnt[0]][cnt[1]][cnt[2]][cnt[3]][cnt[4]][cnt[5]][cnt[6]][cnt[7]][cnt[8]][cnt[9]][mod] = val;
    }

    static void init(int n, int m, char[] c) {

        a = new int[n];

        for (int i = 0; i < n; i++)
            a[n - i - 1] = c[i] - '0';
        int [] cnt = new int [10];
        for(int x : a)
            cnt[x]++;
        memo = new long[n][cnt[0]+1][cnt[1]+1][cnt[2]+1][cnt[3]+1][cnt[4]+1][cnt[5]+1][cnt[6]+1][cnt[7]+1][cnt[8]+1][cnt[9]+1][m+1];

            for (long[][][][][][][][][][][] xx : memo)
                 for (long[][][][][][][][][][] xxx : xx)
                    for (long[][][][][][][][][] xxxx : xxx)
                        for (long[][][][][][][][] xxxxx : xxxx)
                            for (long[][][][][][][] xxxxxx : xxxxx)
                                for (long[][][][][][] xxxxxxx : xxxxxx)
                                    for (long[][][][][] xxxxxxxx : xxxxxxx)
                                        for (long[][][][] xxxxxxxxx : xxxxxxxx)
                                            for (long[][][] xxxxxxxxxx : xxxxxxxxx)
                                                for (long[][] xxxxxxxxxxx : xxxxxxxxxx)
                                                    for (long[] xxxxxxxxxxxx : xxxxxxxxxxx)
                                                        Arrays.fill(xxxxxxxxxxxx, -1);
    }

}