#include <bits/stdc++.h>
using namespace std;
const int DIM = 107;
const int mod = 1e9 + 7;
long long n, k;
struct Matrix {
  int v[DIM][DIM];
  Matrix() { memset(v, 0, sizeof(v)); }
  int *operator[](int x) { return v[x]; }
  friend Matrix operator*(Matrix &a, Matrix &b) {
    Matrix ans;
    for (int i = 0; i < k; i++)
      for (int t = 0; t < k; t++)
        for (int j = 0; j < k; j++)
          ans[i][j] = (ans[i][j] + 1LL * a[i][t] * b[t][j]) % mod;
    return ans;
  }
};
Matrix lgpow(Matrix x, long long n) {
  Matrix ans;
  for (int i = 0; i < k; i++) ans[i][i] = 1;
  while (n) {
    if (n & 1) ans = ans * x;
    x = x * x;
    n >>= 1;
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> k;
  Matrix v;
  for (int i = 1; i < k; i++) v[i - 1][i] = 1;
  v[k - 1][0] = v[k - 1][k - 1] = 1;
  v = lgpow(v, n);
  cout << v[k - 1][k - 1];
}
