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.BufferedReader;
import java.io.FileNotFoundException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashSet;
import java.util.StringTokenizer;

/**
 *
 *
 * 3 2 3 5
 * -2 -1 4 -1 2 7 3
 *
 *
 * @author pttrung
 */
public class D {

    public static long MOD = 100000000;
    public static long[][] dp;

    public static void main(String[] args) throws FileNotFoundException {
        PrintWriter out;
        Scanner in = new Scanner();
        //out = new PrintWriter(new FileOutputStream(new File("output.txt")));
        out = new PrintWriter(System.out);

        long n = in.nextLong();
        int m = in.nextInt();
        int d = digit(n);
        //System.out.println(d);
        dp = new long[1 << d][m];
        for (long[] a : dp) {
            Arrays.fill(a, -1);
        }
        
//        int []or = new int[d];
//        for(int i = 0; i < d; i++){
//            or[i] = i;
//        }
//        String num = "" + n;
//        int test = 0;
//        HashSet<Long> set = new HashSet();
//        do{
//            long val = 0;
//            if(num.charAt(or[0]) == '0'){
//                continue;
//            }
//            for(int i = 0; i < d; i++){
//                int index = num.charAt(or[i]) - '0';
//                
//                val *=10;
//                val += index;
//                
//            }
//            if(val % m == 0){
//               set.add(val);
//            }
//        }while(nextPer(or));
//        out.println(set);
//        out.println(set.size());
        long val = cal(0, 0, m, d, "" + n);
        out.println(val);
        out.close();

    }

    public static long cal(int mask, int mod, int m, int d, String num) {
        if (dp[mask][mod] != -1) {
            return dp[mask][mod];
        }
        int order = 0;
        long add = 1;
        for (int i = 0; i < d; i++) {
            if (((1 << i) & mask) != 0) {
                order++;
                add *= 10;
            }
        }
        //System.out.println("TEST " + mask + " " + order + " " + mod);
        if (order == d && mod == 0) {
            return 1;
        }
        long result = 0;
        boolean[] check = new boolean[10];
        for (int i = 0; i < num.length(); i++) {
            if (((1 << i) & mask) == 0) {
                int cur = num.charAt(i) - '0';
                if (check[cur]) {
                    continue;
                }
                check[cur] = true;
                int c = (int) ((cur % m) * (add % m)) % m;
                int temp = (c + mod) % m;
                // System.out.println(temp + " " + index + " " + order);
                if (cur != 0 || order != num.length() - 1) {
                    result += cal(mask | (1 << i), temp, m, d, num);
                }
            }
        }
        return dp[mask][mod] = result;
    }

    public static boolean nextPer(int[] data) {
        int i = data.length - 1;
        while (i > 0 && data[i] < data[i - 1]) {
            i--;
        }
        if (i == 0) {
            return false;
        }
        int j = data.length - 1;
        while (data[j] < data[i - 1]) {
            j--;
        }
        int temp = data[i - 1];
        data[i - 1] = data[j];
        data[j] = temp;
        Arrays.sort(data, i, data.length);
        return true;
    }

    public static int digit(long n) {
        int result = 0;
        while (n > 0) {
            n /= 10;
            result++;
        }
        return result;
    }

    public static double dist(long a, long b, long x, long y) {
        double val = (b - a) * (b - a) + (x - y) * (x - y);
        val = Math.sqrt(val);
        double other = x * x + a * a;
        other = Math.sqrt(other);
        return val + other;
    }

    public static class Point implements Comparable<Point> {

        int index, value;

        public Point(int start, int end) {
            this.index = start;
            this.value = end;
        }

        @Override
        public int compareTo(Point o) {
            return value - o.value;
        }
    }

    public static class Node implements Comparable<Node> {

        int index;
        int val;

        public Node(int index, int u) {
            this.index = index;
            this.val = u;

        }

        @Override
        public int compareTo(Node o) {
            if (val != o.val) {
                return val - o.val;
            }
            return index - o.index;
        }
    }

    public static class FT {

        int[] data;

        FT(int n) {
            data = new int[n];
        }

        public void update(int index, int value) {
            while (index < data.length) {
                data[index] += value;
                index += (index & (-index));
            }
        }

        public int get(int index) {
            int result = 0;
            while (index > 0) {
                result += data[index];
                index -= (index & (-index));
            }
            return result;

        }
    }

    public static class Sign {

        char c;
        int x, y;

        public Sign(char c, int x, int y) {
            this.c = c;
            this.x = x;
            this.y = y;
        }
    }

    public static long gcd(long a, long b) {
        if (b == 0) {
            return a;
        }
        return gcd(b, a % b);
    }

    public static long pow(long a, long b) {
        if (b == 0) {
            return 1;
        }
        if (b == 1) {
            return a;
        }
        long val = pow(a, b / 2);
        if (b % 2 == 0) {
            return val * val % MOD;
        } else {
            return val * (val * a % MOD) % MOD;
        }
    }

    static class Scanner {

        BufferedReader br;
        StringTokenizer st;

        public Scanner() throws FileNotFoundException {
            // System.setOut(new PrintStream(new BufferedOutputStream(System.out), true));
            br = new BufferedReader(new InputStreamReader(System.in));
            //br = new BufferedReader(new InputStreamReader(new FileInputStream(new File("input.txt"))));
        }

        public String next() {

            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (Exception e) {
                    throw new RuntimeException();
                }
            }
            return st.nextToken();
        }

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

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

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

        public String nextLine() {
            st = null;
            try {
                return br.readLine();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }

        public boolean endLine() {
            try {
                String next = br.readLine();
                while (next != null && next.trim().isEmpty()) {
                    next = br.readLine();
                }
                if (next == null) {
                    return true;
                }
                st = new StringTokenizer(next);
                return st.hasMoreTokens();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }
    }
}
