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.IOException;
import java.util.Arrays;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Mahmoud Aladdin <aladdin3>
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskD solver = new TaskD();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskD {
    int[] input;
    int m;

    long[][] memory = new long[(1 << 18)][101];

    public void solve(int testNumber, InputReader jin, PrintWriter jout) {
        String token = jin.token();
        m = jin.int32();

        input = new int[token.length()];
        for(int i = 0; i < token.length(); i++) {
            input[i] = token.charAt(i) - '0';
        }

        for(long[] r: memory) Arrays.fill(r, -1);

        BigInteger mask = BigInteger.ZERO;
        BigInteger curr = BigInteger.ZERO;
        long res = 0;
        for(int i = 0; i < input.length; i++) {
            if(input[i] != 0) {
                if(curr.testBit(input[i])) continue;
                curr = curr.setBit(input[i]);
                res += bt(mask.setBit(i), input[i] % m, input[i]);
            }
        }
        jout.println(res);
    }

    private long bt(BigInteger mask, int rem, long val) {
        if(mask.intValue() == (1 << input.length) - 1) {
            return rem == 0? 1: 0;
        } else {
            if(memory[mask.intValue()][rem] != -1)
                return memory[mask.intValue()][rem];
            long res = 0;
            BigInteger currMask = BigInteger.ZERO;
            for(int i = 0; i < input.length; i++) {
                if(mask.testBit(i)) continue;
                if(currMask.testBit(input[i])) continue;
                currMask = currMask.setBit(input[i]);
                res += bt(mask.setBit(i), ((rem * 10) + input[i]) % m, val * 10 + input[i]);
            }
            return memory[mask.intValue()][rem] = res;
        }
    }
}

class InputReader {
    private static final int bufferMaxLength = 1024;
    private InputStream in;
    private byte[] buffer;
    private int currentBufferSize;
    private int currentBufferTop;
    private static final String tokenizers = " \t\r\f\n";
    
    public InputReader(InputStream stream) {
        this.in = stream;
        buffer = new byte[bufferMaxLength];
        currentBufferSize = 0;
        currentBufferTop = 0;
    }
    
    private boolean refill() {
        try {
            this.currentBufferSize = this.in.read(this.buffer);
            this.currentBufferTop = 0;
        } catch(Exception e) {}
        return this.currentBufferSize > 0;
    }
    
    
    private Byte readChar() {
        if(currentBufferTop < currentBufferSize) {
            return this.buffer[this.currentBufferTop++];
        } else {
            if(!this.refill()) {
                return null;
            } else {
                return readChar();
            }
        }
    }

    public String token()  {
        StringBuffer tok = new StringBuffer();
        Byte first;
        while((first = readChar()) != null && (tokenizers.indexOf((char) first.byteValue()) != -1));
        if(first == null) return null;
        tok.append((char)first.byteValue());
        while((first = readChar()) != null && (tokenizers.indexOf((char) first.byteValue()) == -1)) {
            tok.append((char)first.byteValue());
        }
        return tok.toString();
    }
    
    public Integer int32() throws NumberFormatException {
        String tok = token();
        return tok == null? null : Integer.parseInt(tok);
    }

    }

