#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const double eps = 1e-6;
const int maxn = 2e5 + 10;
struct Matrix {
  int mat[110][110], n;
  Matrix() {}
  Matrix(int _n) {
    n = _n;
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++) mat[i][j] = 0;
  }
  Matrix operator*(const Matrix &b) const {
    Matrix ret = Matrix(n);
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++)
        for (int k = 0; k < n; k++) {
          int tmp = (long long)mat[i][k] * b.mat[k][j] % mod;
          ret.mat[i][j] = (ret.mat[i][j] + tmp) % mod;
        }
    return ret;
  }
};
Matrix pow_M(Matrix a, long long n) {
  Matrix ret = Matrix(a.n);
  for (int i = 0; i < ret.n; i++) ret.mat[i][i] = 1;
  Matrix tmp = a;
  while (n) {
    if (n & 1) ret = ret * tmp;
    tmp = tmp * tmp;
    n /= 2;
  }
  return ret;
}
int main() {
  long long n;
  int m;
  cin >> n >> m;
  if (n < m) {
    cout << 1 << endl;
    return 0;
  }
  Matrix Mat(m);
  Matrix ans(m);
  Mat.mat[0][0] = 1;
  Mat.mat[0][m - 1] = 1;
  for (int i = 0; i < m; i++) ans.mat[i][0] = 1;
  ans.mat[0][0] = 2;
  for (int i = 1; i < m; i++) Mat.mat[i][i - 1] = 1;
  Mat = pow_M(Mat, n - m);
  ans = Mat * ans;
  cout << ans.mat[0][0] % mod << endl;
}
