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;
const long double pi = 3.14159265359;
template <typename T>
T abs(T x) {
  return x > 0 ? x : -x;
}
template <typename T>
T sqr(T x) {
  return x * x;
}
const long long mod = 1000000007;
const int maxn = 31;
int k;
struct matr {
  long long a[maxn][maxn];
  matr() {
    for (int i = 0; i < k + 1; i++)
      for (int j = 0; j < k + 1; j++) a[i][j] = 0;
  }
  matr operator*(const matr &other) const {
    matr res;
    long long mod2 = mod * mod;
    for (int i = 0; i < k + 1; i++)
      for (int j = 0; j < k + 1; j++) {
        for (int h = 0; h < k + 1; h++) {
          res.a[i][j] += a[i][h] * other.a[h][j];
          if (res.a[i][j] >= mod2) res.a[i][j] -= mod2;
        }
        res.a[i][j] %= mod;
      }
    return res;
  }
};
map<pair<int, int>, matr> cache;
matr rot(const matr &x, int add) {
  matr res;
  for (int i = 0; i < k; i++)
    for (int j = 0; j < k; j++) res.a[(i + add) % k][(j + add) % k] = x.a[i][j];
  for (int i = 0; i < k; i++) res.a[(i + add) % k][k] = x.a[i][k];
  res.a[k][k] = 1;
  return res;
}
matr get(int n, int add) {
  if (cache.find(make_pair(n, add)) != cache.end())
    return cache[make_pair(n, add)];
  matr res;
  if (n == 0) {
    if (add == 0) {
      for (int i = 0; i <= k; i++) res.a[0][i] = 1;
      for (int i = 1; i <= k; i++) res.a[i][i] = 1;
    } else {
      res = rot(get(n, add - 1), 1);
    }
    return cache[make_pair(n, add)] = res;
  } else {
    if (add == 0) {
      res = get(n - 1, 0);
      for (int i = 1; i < k; i++) res = get(n - 1, i) * res;
    } else {
      res = rot(get(n, add - 1), 1);
    }
    return cache[make_pair(n, add)] = res;
  }
}
int main() {
  long long n;
  cin >> n >> k;
  matr ans;
  for (int i = 0; i < k + 1; i++) ans.a[i][i] = 1;
  int add = 0;
  while (n) {
    long long g = 1;
    int pw = 0;
    while (g <= (n / k + 5) && g * k <= n) {
      g *= k;
      pw++;
    }
    while (g <= n) {
      ans = get(pw, add % k) * ans;
      add++;
      n -= g;
    }
  }
  long long ans2 = 1;
  for (int i = 0; i < k; i++) ans2 = (ans2 + ans.a[i][k]) % mod;
  cout << ans2 << endl;
  return 0;
}