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

public class Main {
    FastScanner in;
    PrintWriter out;
    final int DIGITS = 10;
    int[] cnt = new int[DIGITS];

    class Masks implements Comparable<Masks>{
        int x, y;

        Masks(int x, int y) {
            this.x = x;
            this.y = y;
        }

        @Override
        public int compareTo(Masks o) {
            return Integer.compare(o.y, y);
        }
    }

    int decrMask(int x, int pos) {
        int pw = 1;
        for (int i = DIGITS - 1; i > pos; --i)
            pw *= cnt[i] + 1;
        int car = x % pw;
        x /= pw;
        --x;
        return x * pw + car;
    }
    int getBit(int x, int pos) {
        int pw = 1;
        for (int i = DIGITS - 1; i > pos; --i)
            pw *= cnt[i] + 1;
        return x / pw % (cnt[pos] + 1);
    }

    int cntBits(int x) {
        int ret = 0;
        for (int i = 0; i < DIGITS; ++i)
            ret += getBit(x, i);
        return ret;
    }

    public void solve() throws IOException {
        long n = in.nextLong();
        int m = in.nextInt();
        long nn = n;
        int len = 0;
        while (nn > 0) {
            cnt[(int)(nn % DIGITS)]++;
            nn /= 10;
            ++len;
        }
        int tot = 1;
        for (int i = 0; i < DIGITS; ++i)
            tot *= cnt[i] + 1;

        Masks[] ms = new Masks[tot];
        for (int i = 0; i < tot; ++i)
            ms[i] = new Masks (i, cntBits(i));
        Arrays.sort(ms);
        //System.out.println(decrMask(7, 1));
        long[][] dp = new long[tot][m];
        dp[tot - 1][0] = 1;
        for (int i = 0; i < tot; ++i) {
            int curms = ms[i].x;
            int beg = 0;
            if (i == 0) beg = 1;
            for (int dig = beg; dig < DIGITS; ++dig)
                if (getBit(curms, dig) > 0)
                  for (int ost = 0; ost < m; ++ost) {
                      //System.out.println(curms + " " + decrMask(curms, dig));
                      dp[decrMask(curms, dig)][(ost * DIGITS + dig) % m] += dp[curms][ost];
                  }
        }
        out.println(dp[0][0]);
    }

    void run() {
        try {
            in = new FastScanner();
            out = new PrintWriter(new OutputStreamWriter(System.out));

            solve();

            out.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        FastScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
    }

    public static void main(String[] arg) {
        new Main().run();
        //run();
    }
}