#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5, M = 5e5 + 9, MOD = 1e9 + 7;
vector<vector<int>> trans, ret;
int kk;
int mul(int a, int b) { return (1ll * a * b) % MOD; }
int add(long long x, int y) {
  x += y;
  while (x >= MOD) x -= MOD;
  while (x < 0) x += MOD;
  return x;
}
vector<vector<int>> mulMat(vector<vector<int>> &a, vector<vector<int>> &b) {
  vector<vector<int>> c;
  c.resize(kk);
  for (int i = 0; i < kk; ++i) c[i] = vector<int>(kk, 0);
  for (int i = 0; i < kk; ++i) {
    for (int j = 0; j < kk; ++j) {
      for (int k = 0; k < kk; ++k) {
        c[i][k] = add(c[i][k], mul(a[i][j], b[j][k]));
      }
    }
  }
  return c;
}
vector<vector<int>> fastpow(long long b) {
  ret.resize(kk);
  for (int i = 0; i < kk; ++i) ret[i] = vector<int>(kk, 0);
  for (int i = 0; i < kk; ++i) ret[i][i] = 1;
  while (b) {
    if (b & 1) ret = mulMat(ret, trans);
    b /= 2;
    trans = mulMat(trans, trans);
  }
  return ret;
}
void runtestcase() {
  long long n;
  cin >> n >> kk;
  trans.resize(kk);
  for (int i = 0; i < kk; ++i) trans[i] = vector<int>(kk, 0);
  trans[0][0] = 1;
  for (int i = 1; i < kk; ++i) trans[i][i - 1] = 1;
  trans[0][kk - 1] = 1;
  vector<vector<int>> ans = fastpow(n);
  cout << ans[0][0];
}
int main() {
  cout << fixed << setprecision(12), ios::sync_with_stdio(false),
      cin.tie(nullptr), cout.tie(nullptr);
  int t = 1, tt = 1;
  while (t) {
    runtestcase();
    cout << '\n';
    --t, ++tt;
  }
}
