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.
#include <bits/stdc++.h>
using namespace std;
template <class T>
T abs(T x) {
  return x > 0 ? x : -x;
}
long long n;
int m;
int c[10];
int i[10];
int d[18];
int main() {
  scanf("%I64d %d", &n, &m);
  for (int j = 0; j < 10; ++j) c[j] = 0;
  for (; n > 0; n /= 10) ++c[n % 10];
  long long f[c[0] + 1][c[1] + 1][c[2] + 1][c[3] + 1][c[4] + 1][c[5] + 1]
             [c[6] + 1][c[7] + 1][c[8] + 1][c[9] + 1][m];
  memset(f, 0, sizeof f);
  bool all = true;
  f[0][0][0][0][0][0][0][0][0][0][0] = 1;
  for (i[0] = 0; i[0] <= c[0]; ++i[0])
    for (i[1] = 0; i[1] <= c[1]; ++i[1])
      for (i[2] = 0; i[2] <= c[2]; ++i[2])
        for (i[3] = 0; i[3] <= c[3]; ++i[3])
          for (i[4] = 0; i[4] <= c[4]; ++i[4])
            for (i[5] = 0; i[5] <= c[5]; ++i[5])
              for (i[6] = 0; i[6] <= c[6]; ++i[6])
                for (i[7] = 0; i[7] <= c[7]; ++i[7])
                  for (i[8] = 0; i[8] <= c[8]; ++i[8])
                    for (i[9] = 0; i[9] <= c[9]; ++i[9]) {
                      for (int j = 0; j < m; ++j)
                        for (int k = 0; k < 10; ++k)
                          if (i[k] < c[k] and (!all or (all and k))) {
                            long long add = f[i[0]][i[1]][i[2]][i[3]][i[4]]
                                             [i[5]][i[6]][i[7]][i[8]][i[9]][j];
                            ++i[k];
                            f[i[0]][i[1]][i[2]][i[3]][i[4]][i[5]][i[6]][i[7]]
                             [i[8]][i[9]][(j * 10 + k) % m] += add;
                            --i[k];
                          }
                      all = false;
                    }
  printf("%I64d\n",
         f[c[0]][c[1]][c[2]][c[3]][c[4]][c[5]][c[6]][c[7]][c[8]][c[9]][0]);
  return 0;
}
