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.
/**
 * ******* Created  on 20/12/19 9:09 PM*******
 */

import java.io.*;
import java.util.*;

public class D401 implements Runnable {

    private static final int MAX =3* (int) (1E5 + 5);
    private static final int MOD = (int) (1E9 + 7);
    private static final long Inf = (long) (1E14 + 10);
    long[][]dp = new long[MAX][105];
    private void solve() throws IOException {
        long n = reader.nextLong();
        int m = reader.nextInt();
        int[] has =  new int[20];
        int[] cnt = new int[10];
        int id =0;
        int[] pw = new int[20];
        long[] fac = new long[20];
        while (n > 0) {
            has[id++] = (int) (n % 10L); cnt[(int) (n % 10)]++;
            n /= 10;
        }
        pw[0] = 1 % m;
        for (int i = 1; i < id; i++)
            pw[i] = 10 * pw[i - 1] % m;
        fac[0] = 1;
        for (int i = 1; i <= id; i++)
            fac[i] = fac[i - 1] * i;
        dp[0][0] =1;
        for(int i=0;i<(1<<id);i++){
            int b =0;
            for(int j=0;j<id;j++){
                if( (i&(1<<j)) >0)b++;
            }
            for(int j =0;j<m;j++)if(dp[i][j]!=0){
                for(int k =0;k<id;k++){
                    if(( !((i & (1<<k))> 0) &&(k+1< id || has[b] !=0) )) {
                        int x = (int) ((has[b]*pw[k] + j)%m);
                        dp[i | (1<<k)][x] = (dp[i | (1<<k)][x] + dp[i][j]);

                    }
                }
            }
        }
        long ans = dp[(1<<id)-1][0];
        for(int i =0;i<10;i++)
            ans /= fac[cnt[i]];
        writer.println(ans);
    }

    public static void main(String[] args) throws IOException {
        try (Input reader = new StandardInput(); PrintWriter writer = new PrintWriter(System.out)) {
            new D401().run();
        }
    }

    StandardInput reader;
    PrintWriter writer;

    @Override
    public void run() {
        try {
            reader = new StandardInput();
            writer = new PrintWriter(System.out);
            solve();
            reader.close();
            writer.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    interface Input extends Closeable {
        String next() throws IOException;

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

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

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

        default int[] readIntArray() throws IOException {
            return readIntArray(nextInt());
        }

        default int[] readIntArray(int size) throws IOException {
            int[] array = new int[size];
            for (int i = 0; i < array.length; i++) {
                array[i] = nextInt();
            }
            return array;
        }

        default long[] readLongArray(int size) throws IOException {
            long[] array = new long[size];
            for (int i = 0; i < array.length; i++) {
                array[i] = nextLong();
            }
            return array;
        }
    }

    private static class StandardInput implements Input {
        private final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

        private StringTokenizer stringTokenizer;

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

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