#include <bits/stdc++.h>
using namespace std;
long long modpow(long long a, long long b,
                 long long mod = (long long)(1e9 + 7)) {
  if (!b) return 1;
  a %= mod;
  return modpow(a * a % mod, b / 2, mod) * (b & 1 ? a : 1) % mod;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const long long mod = 1e9 + 7;
long long n;
int m;
struct Matrix {
  long long a[100][100];
  Matrix() {
    for (int i = 0; i < m; i++)
      for (int j = 0; j < m; j++) a[i][j] = 0;
  }
  Matrix multiply(Matrix b) {
    Matrix res;
    for (int i = 0; i < m; i++)
      for (int j = 0; j < m; j++)
        for (int k = 0; k < m; k++)
          res.a[i][k] = (res.a[i][k] + a[i][j] * b.a[j][k]) % mod;
    return res;
  }
  void setBase() {
    a[0][0] = 1;
    a[0][m - 1] = 1;
    for (int i = 1; i <= m; i++) a[i][i - 1] = 1;
  }
  void print() {
    for (int i = 0; i < m + 1; i++) {
      for (int j = 0; j < m + 1; j++) cout << a[i][j] << " ";
      cout << endl;
    }
    cout << endl;
  }
};
Matrix identity;
void init() {
  for (int i = 0; i < 100; i++) identity.a[i][i] = 1;
}
Matrix matrixPow(Matrix a, long long b) {
  if (!b) return identity;
  return matrixPow(a.multiply(a), b / 2).multiply(b & 1 ? a : identity);
}
void solve() {
  init();
  Matrix base;
  base.setBase();
  Matrix res = matrixPow(base, n);
  Matrix eval;
  eval.a[0][0] = 1;
  Matrix ans = res.multiply(eval);
  cout << ans.a[0][0] << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  while (cin >> n >> m) solve();
  return 0;
}
