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.
//package codeforces;

import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class D implements Closeable {
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    PrintWriter writer = new PrintWriter(System.out);
    StringTokenizer stringTokenizer;

    String next() throws IOException {
        while (stringTokenizer == null || !stringTokenizer.hasMoreTokens()) {
            stringTokenizer = new StringTokenizer(reader.readLine());
        }
        return stringTokenizer.nextToken();
    }

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

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

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

    int MOD = 1000 * 1000 * 1000 + 7;

    int sum(int a, int b) {
        a += b;
        return a >= MOD ? a - MOD : a;
    }

    int product(int a, int b) {
        return (int) (1l * a * b % MOD);
    }

    @SuppressWarnings("unchecked")
    void solve() throws IOException {
        long n = nextLong();
        final int m = nextInt();
        List<Integer> digits = new ArrayList<>();
        for(long i = n; i > 0; i /= 10) {
            digits.add((int)(i % 10));
        }
        Collections.sort(digits);
        final int[] d = new int[digits.size()];
        for(int i = 0; i < digits.size(); i++) {
            d[i] = digits.get(i);
        }
        class Utils {
            final boolean bitIsSet(int mask, int bit) {
                return (mask & (1 << bit)) > 0;
            }

            long rec(int mask, int mod) {
                if(mask == (1 << d.length) - 1) {
                    return mod == 0 ? 1 : 0;
                }
                long result = 0;
                for(int i = 0; i < d.length; i++) {
                    if(mask == 0 && d[i] == 0) {
                        continue;
                    }
                    if(!bitIsSet(mask, i)) {
                        if(i > 0 && d[i] == d[i - 1] && !bitIsSet(mask, i - 1)) {
                            continue;
                        }
                        result += rec(mask | (1 << i), (mod * 10 + d[i]) % m);
                    }
                }
                return result;
            }
        }
        class CachedUtils extends Utils {
            boolean[][] hit = new boolean[1 << d.length][m];
            long[][] cache = new long[1 << d.length][m];

            @Override
            long rec(int mask, int mod) {
                if(!hit[mask][mod]) {
                    cache[mask][mod] = super.rec(mask, mod);
                    hit[mask][mod] = true;
                }
                return cache[mask][mod];
            }
        }
        writer.println(new CachedUtils().rec(0, 0));
    }

    public static void main(String[] args) throws IOException, InterruptedException {
        try (D d = new D()) {
            d.solve();
        }
    }

    @Override
    public void close() throws IOException {
        reader.close();
        writer.close();
    }
}