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;
struct ju {
  long long a[110][110];
} g[65];
struct xiang {
  long long a[110];
} an;
long long n, k, a[65], na, ansn;
xiang operator*(xiang x, ju y) {
  xiang z;
  for (int i = 0; i <= k; i++) {
    z.a[i] = 0;
    for (int j = 0; j <= k; j++)
      z.a[i] = (z.a[i] + x.a[j] * y.a[i][j]) % 1000000007;
  }
  return z;
}
ju operator*(ju x, ju y) {
  ju z;
  for (int i = 0; i <= k; i++) {
    for (int j = 0; j <= k; j++) {
      z.a[i][j] = 0;
      for (int l = 0; l <= k; l++)
        z.a[i][j] = (z.a[i][j] + x.a[l][j] * y.a[i][l]) % 1000000007;
    }
  }
  return z;
}
ju yi(ju x, int y) {
  ju z;
  for (int i = 0, ni, nj; i <= k; i++) {
    for (int j = 0; j <= k; j++) {
      if (i == k)
        ni = k;
      else
        ni = (i + y) % k;
      if (j == k)
        nj = k;
      else
        nj = (j + y) % k;
      z.a[ni][nj] = x.a[i][j];
    }
  }
  return z;
}
ju po(ju x, int y) {
  if (y == 1) return x;
  ju z = po(x, y / 2);
  z = z * yi(z, y / 2);
  if (y % 2 == 1) z = z * yi(x, y - 1);
  return z;
}
int main() {
  cin >> n >> k;
  for (long long i = n; i; i = i / k) a[++na] = i % k;
  for (int i = 0; i <= k; i++) g[0].a[i][i] = 1;
  for (int i = 1; i <= k; i++) g[0].a[0][i] = 1;
  for (int i = 1; i < na; i++) g[i] = po(g[i - 1], k);
  for (int i = 0; i < k; i++) an.a[i] = 0;
  an.a[k] = 1;
  for (int i = na, su = 0; i >= 1; i--) {
    if (a[i]) an = an * po(yi(g[i - 1], su), a[i]);
    su += a[i];
  }
  for (int i = 0; i <= k; i++) ansn = (ansn + an.a[i]) % 1000000007;
  cout << ansn << endl;
  return 0;
}