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.

/* 
Keep solving problems. 
*/
import java.util.*;
import java.io.*;

public class CF401D {

    BufferedReader br;
    PrintWriter out;
    StringTokenizer st;
    boolean eof;
    final long MOD = 1000L * 1000L * 1000L + 7;
    long[][] dp;
    char[] arr;
    int n;
    int m;
    void solve() throws IOException {
        arr = Long.toString(nextLong()).toCharArray();
        m = nextInt();
        n = arr.length;

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

        for(int mask = 0; mask < (1 << n); mask++) {
            for(int rem = 0; rem < m; rem++) {
                if(dp[mask][rem] == 0) {
                    continue;
                }

                for(int i = 0; i < n; i++) {
                    if((mask & (1 << i)) == 0) {
                        if(!(mask == 0 && arr[i] == '0')) {
                            dp[mask + (1 << i)][(rem * 10 + (arr[i] - '0')) % m] += dp[mask][rem];
                        }
                    }
                }
            }
        }

        int[] hist = new int[10];
        for(int i = 0; i < n; i++) {
            hist[arr[i] - '0']++;
        }
        long[] fact = new long[20];
        fact[0] = 1;
        for(int i = 1; i < 20; i++) {
            fact[i] = fact[i - 1] * i;
        }
        long res = dp[(1 << n) - 1][0];
        for(int i = 0; i < hist.length; i++) {
            res /= fact[hist[i]];
        }
        out(res);
    }

    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;
        }
    }
    private void outln(Object o) {
        out.println(o);
    }
    private void out(Object o) {
        out.print(o);
    }
    public CF401D() throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }
    public static void main(String[] args) throws IOException {
        new CF401D();
    }

    public long[] nextLongArr(int n) throws IOException{
        long[] res = new long[n];
        for(int i = 0; i < n; i++)
            res[i] = nextLong();
        return res;
    }
    public int[] nextIntArr(int n) throws IOException {
        int[] res = new int[n];
        for(int i = 0; i < n; i++)
            res[i] = nextInt();
        return res;
    }
    public String nextToken() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                eof = true;
                return null;
            }
        }
        return st.nextToken();
    }
    public String nextString() {
        try {
            return br.readLine();
        } catch (IOException e) {
            eof = true;
            return null;
        }
    }
    public int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }
    public long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }
    public double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }
}

