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.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.FilterInputStream;
import java.io.BufferedInputStream;
import java.io.InputStream;

/**
 * @author khokharnikunj8
 */

public class Main {
    public static void main(String[] args) {
        new Thread(null, new Runnable() {
            public void run() {
                new Main().solve();
            }
        }, "1", 1 << 26).start();
    }

    void solve() {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        ScanReader in = new ScanReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DRomanAndNumbers solver = new DRomanAndNumbers();
        solver.solve(1, in, out);
        out.close();
    }

    static class DRomanAndNumbers {
        public void solve(int testNumber, ScanReader in, PrintWriter out) {
            char[] s = in.scanString().toCharArray();
            int m = in.scanInt();
            long[][] dp = new long[1 << s.length][m];
            for (int i = 0; i < s.length; i++) {
                if (s[i] != '0') dp[1 << i][(s[i] - '0') % m] = 1;
            }
            int[] si = new int[s.length];
            for (int i = 0; i < s.length; i++) si[i] = s[i] - '0';
            long[] fact = new long[20];
            fact[0] = 1;
            for (int i = 1; i < 20; i++) fact[i] = fact[i - 1] * i;
            for (int i = 1; i < 1 << s.length; i++) {
                for (int j = 0; j < m; j++) {
                    if (dp[i][j] == 0) continue;
                    for (int k = 0; k < s.length; k++) {
                        if ((i & (1 << k)) == 0) {
                            dp[i ^ (1 << k)][(j * 10 + (si[k])) % m] += dp[i][j];
                        }
                    }
                }
            }
            long ans = dp[(1 << s.length) - 1][0];
            int[] count = new int[10];
            for (char c : s) count[c - '0']++;
            for (int i : count) ans /= fact[i];
            out.println(ans);

        }

    }

    static class ScanReader {
        private byte[] buf = new byte[4 * 1024];
        private int index;
        private BufferedInputStream in;
        private int total;

        public ScanReader(InputStream inputStream) {
            in = new BufferedInputStream(inputStream);
        }

        private int scan() {
            if (index >= total) {
                index = 0;
                try {
                    total = in.read(buf);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if (total <= 0) return -1;
            }
            return buf[index++];
        }

        public int scanInt() {
            int integer = 0;
            int n = scan();
            while (isWhiteSpace(n)) n = scan();
            int neg = 1;
            if (n == '-') {
                neg = -1;
                n = scan();
            }
            while (!isWhiteSpace(n)) {
                if (n >= '0' && n <= '9') {
                    integer *= 10;
                    integer += n - '0';
                    n = scan();
                }
            }
            return neg * integer;
        }

        public String scanString() {
            int c = scan();
            if (c == -1) return null;
            while (isWhiteSpace(c)) c = scan();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = scan();
            } while (!isWhiteSpace(c));
            return res.toString();
        }

        private boolean isWhiteSpace(int n) {
            if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1) return true;
            else return false;
        }

    }
}

