#include <bits/stdc++.h>
using namespace std;
vector<vector<long long>> matrixMul(vector<vector<long long>> lft,
                                    vector<vector<long long>> rit,
                                    long long mod = 1e9 + 7) {
  int n = lft.size(), s = rit.size(), m = rit.back().size();
  vector<vector<long long>> res(n, vector<long long>(m, 0));
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j)
      for (int k = 0; k < s; ++k)
        res[i][j] = (res[i][j] + lft[i][k] * rit[k][j]) % mod;
  return res;
}
vector<vector<long long>> matrixPow(vector<vector<long long>> base,
                                    long long exp, long long mod = 1e9 + 7) {
  int n = base.size();
  vector<vector<long long>> res(n, vector<long long>(n, 0));
  for (int i = 0; i < n; ++i) res[i][i] = 1;
  for (; exp; exp >>= 1, base = matrixMul(base, base, mod))
    if (exp & 1) res = matrixMul(res, base, mod);
  return res;
}
int main() {
  long long n, m;
  cin >> n >> m;
  vector<vector<long long>> mat;
  mat.resize(m);
  for (int i = 0; i < m; ++i) mat[i].resize(m);
  for (int i = 0; i < m; ++i)
    for (int j = 0; j < m; ++j) {
      mat[i][j] = 0;
    }
  for (int i = 1; i < m; ++i) mat[i][i - 1] = 1;
  mat[0][0] = 1;
  mat[0][m - 1] = 1;
  cout << matrixPow(mat, n)[0][0];
}
