#include <bits/stdc++.h>
using namespace std;
long long n, m;
struct Matrix {
  vector<vector<long long> > mat;
  Matrix() {}
  Matrix(int m) { mat.resize(m, vector<long long>(m)); }
};
long long MOD = 1e9 + 7;
inline Matrix matMul(Matrix a, Matrix b) {
  Matrix ans = Matrix(m);
  long long i, j, k;
  for (i = 0; i < m; i++)
    for (j = 0; j < m; j++)
      for (ans.mat[i][j] = k = 0; k < m; k++) {
        ans.mat[i][j] += a.mat[i][k] * b.mat[k][j];
        ans.mat[i][j] %= MOD;
      }
  return ans;
}
Matrix matPow(Matrix base, long long p) {
  Matrix ans = Matrix(m);
  long long i, j;
  for (i = 0; i < m; i++)
    for (j = 0; j < m; j++) ans.mat[i][j] = (i == j);
  while (p) {
    if (p & 1) ans = matMul(ans, base);
    base = matMul(base, base);
    p >>= 1;
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie();
  cout.tie();
  cin >> n >> m;
  if (n < m) return cout << 1 << endl, 0;
  Matrix base = Matrix(m);
  for (int i = 0; i < m; i++)
    for (int j = 0; j < m; j++) base.mat[i][j] = 0;
  for (int i = 0; i < m - 1; i++) base.mat[0][i] = 1;
  base.mat[0][m - 1] = 2;
  Matrix trans = Matrix(m);
  for (int i = 0; i < m; i++)
    for (int j = 0; j < m; j++) trans.mat[i][j] = 0;
  for (int i = 0; i < m - 1; i++) trans.mat[i + 1][i] = 1;
  trans.mat[0][m - 1] = trans.mat[m - 1][m - 1] = 1;
  Matrix res = matPow(trans, n - m);
  Matrix ans = matMul(base, res);
  cout << ans.mat[0][m - 1] << endl;
  return 0;
}
