Problem: Assume that sk(n) equals the sum of digits of number n in the k-based notation. For example, s2(5) = s2(1012) = 1 + 0 + 1 = 2, s3(14) = s3(1123) = 1 + 1 + 2 = 4.

The sequence of integers a0, ..., an - 1 is defined as <image>. Your task is to calculate the number of distinct subsequences of sequence a0, ..., an - 1. Calculate the answer modulo 109 + 7.

Sequence a1, ..., ak is called to be a subsequence of sequence b1, ..., bl, if there is a sequence of indices 1 ≤ i1 < ... < ik ≤ l, such that a1 = bi1, ..., ak = bik. In particular, an empty sequence (i.e. the sequence consisting of zero elements) is a subsequence of any sequence.

Input

The first line contains two space-separated numbers n and k (1 ≤ n ≤ 1018, 2 ≤ k ≤ 30).

Output

In a single line print the answer to the problem modulo 109 + 7.

Examples

Input

4 2


Output

11


Input

7 7


Output

128

Note

In the first sample the sequence ai looks as follows: (0, 1, 1, 0). All the possible subsequences are: 

(), (0), (0, 0), (0, 1), (0, 1, 0), (0, 1, 1), (0, 1, 1, 0), (1), (1, 0), (1, 1), (1, 1, 0).

In the second sample the sequence ai looks as follows: (0, 1, 2, 3, 4, 5, 6). The subsequences of this sequence are exactly all increasing sequences formed from numbers from 0 to 6. It is easy to see that there are 27 = 128 such sequences.

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
long long n;
int p, q[110], tot, ans, bn[110];
struct Vec {
  int a[35];
} A;
struct Mtx {
  int a[35][35];
} f[110][35];
inline void Add(int &a, int b) {
  a += b;
  if (a >= 1000000007) a -= 1000000007;
}
inline Mtx Mul(Mtx a, Mtx b) {
  Mtx c;
  memset(c.a, 0, sizeof(c.a));
  for (int k = 0; k <= p; k++)
    for (int i = 0; i <= p; i++)
      for (int j = 0; j <= p; j++)
        Add(c.a[i][j], a.a[i][k] * 1ll * b.a[k][j] % 1000000007);
  return (c);
}
inline Vec Meg(Vec a, Mtx b) {
  Vec c;
  memset(c.a, 0, sizeof(c.a));
  for (int j = 0; j <= p; j++)
    for (int i = 0; i <= p; i++)
      Add(c.a[j], a.a[i] * 1ll * b.a[i][j] % 1000000007);
  return (c);
}
int main() {
  scanf("%I64d%d", &n, &p);
  if (!n) {
    puts("2");
    return (0);
  }
  bn[0] = 1;
  for (int i = 1; i <= 70; i++) bn[i] = bn[i - 1] * 10 % p;
  for (int i = 1; i <= 70; i++) {
    if (i != 1)
      f[i][0] = f[i - 1][p - 1];
    else {
      for (int k = 0; k <= p; k++) f[i][0].a[k][0] = 1;
      for (int k = 0; k <= p; k++) f[i][0].a[k][k] = 1;
    }
    for (int j = 1; j < p; j++) {
      Mtx nw;
      memset(nw.a, 0, sizeof(nw.a));
      if (i != 1) {
        for (int h = 0; h < p; h++)
          for (int k = 0; k < p; k++)
            nw.a[(h + j) % p][(k + j) % p] = f[i - 1][p - 1].a[h][k];
        for (int h = 0; h < p; h++)
          nw.a[p][(h + j) % p] = f[i - 1][p - 1].a[p][h];
        nw.a[p][p] = 1;
      } else {
        for (int k = 0; k <= p; k++) nw.a[k][j % p] = 1;
        for (int k = 0; k <= p; k++) nw.a[k][k] = 1;
      }
      if (i == 1)
        f[i][j] = Mul(f[i][j - 1], nw);
      else {
        f[i][j] = f[i][j - 1];
        f[i][j] = Mul(f[i][j], nw);
      }
    }
  }
  A.a[p] = 1;
  while (n) q[++tot] = n % p, n /= p;
  for (int w = 0, i = tot; i; w = q[i], i--) {
    Vec A_;
    memset(A_.a, 0, sizeof(A_.a));
    for (int j = 0; j < p; j++) Add(A_.a[(j - w + p) % p], A.a[j]);
    A_.a[p] = 1;
    if (q[i])
      A = Meg(A_, f[i][q[i] - 1]);
    else
      A = A_;
  }
  for (int i = 0; i <= p; i++) Add(ans, A.a[i]);
  printf("%d\n", ans);
}