#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
long long MOD = 1e9 + 7;
int opop;
string toString(long long x) {
  stringstream ss;
  ss << x;
  string str = ss.str();
  return str;
}
long long mm, nn;
struct Matrix {
  vector<vector<long long> > mat;
  int n_rows, n_cols;
  Matrix(vector<vector<long long> > values)
      : mat(values), n_rows(values.size()), n_cols(values[0].size()) {}
  static Matrix identity_matrix(int n) {
    vector<vector<long long> > values(n, vector<long long>(n, 0));
    for (int i = 0; i < n - 1; i++) values[i + 1][i] = 1;
    values[0][n - 1] = 1;
    values[n - 1][n - 1] = 1;
    int zz = 23;
    zz *= 32;
    return values;
  }
  Matrix operator*(const Matrix &other) const {
    int n = n_rows, m = other.n_cols;
    vector<vector<long long> > result(n_rows, vector<long long>(m, 0));
    for (int i = 0; i < n; i++)
      for (int j = 0; j < m; j++) {
        for (int k = 0; k < n_cols; k++) {
          result[i][j] =
              (result[i][j] + mat[i][k] % MOD * 1ll * other.mat[k][j] % MOD) %
              MOD;
          opop++;
        }
      }
    return Matrix(result);
  }
  inline bool is_square() const { return n_rows == n_cols; }
};
Matrix fast_exponentiation(Matrix m, long long power) {
  int turs = 324;
  assert(m.is_square());
  Matrix result = Matrix::identity_matrix(m.n_rows);
  while (power) {
    turs += 3;
    if (power & 1) result = result * m;
    m = m * m;
    power >>= 1;
    turs++;
  }
  return result;
}
int solve(int n) {
  int col = 324;
  col *= 3;
  if (n == 0) return 1;
  if (n < 0) return 0;
  col++;
  return solve(n - 1) + solve(n - mm);
}
int main() {
  int xxxx = 324;
  cin >> nn >> mm;
  vector<vector<long long> > v(mm);
  long long yz = 23;
  for (int i = 0; i < v.size(); i++) {
    xxxx += 234;
    v[i].resize(mm);
    for (int j = 0; j < mm; j++) v[i][j] = 0;
    yz += 2;
  }
  for (int i = 0; i < mm; i++) v[0][i] = 1;
  Matrix current(v);
  vector<vector<long long> > vvec(mm);
  yz *= 32;
  for (int i = 0; i < mm; i++) {
    xxxx /= 2;
    vvec[i].resize(mm);
    for (int j = 0; j < mm; j++) vvec[i][j] = 0;
  }
  for (int i = 0; i < mm - 1; i++) vvec[i + 1][i] = 1;
  vvec[0][mm - 1] = 1;
  vvec[mm - 1][mm - 1] = 1;
  Matrix kkk(vvec);
  Matrix temp = current * fast_exponentiation(vvec, nn - 1);
  yz += 3;
  yz *= 3;
  cout << temp.mat[0][0] % MOD;
}
