#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
long long dp[100100];
vector<vector<long long>> mult(const vector<vector<long long>>& a,
                               const vector<vector<long long>>& b) {
  int n = a.size();
  int m = b[0].size();
  vector<vector<long long>> c(n, vector<long long>(m));
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      c[i][j] = 0;
      for (int k = 0; k < n; ++k) {
        c[i][j] = (c[i][j] + a[i][k] * b[k][j]) % MOD;
      }
    }
  }
  return c;
}
vector<vector<long long>> pow(vector<vector<long long>> b, long long p) {
  int n = b.size();
  vector<vector<long long>> ans(n, vector<long long>(n, 0));
  for (int i = 0; i < n; ++i) ans[i][i] = 1;
  while (p > 0) {
    if (p & 1) ans = mult(ans, b);
    b = mult(b, b);
    p >>= 1;
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  map<vector<long long>, int> foll;
  long long n, m;
  cin >> n >> m;
  dp[0] = 1;
  for (int i = 1; i <= m * 2; ++i) {
    dp[i] = dp[i - 1];
    if (i - m >= 0) {
      dp[i] += dp[i - m];
      if (dp[i] > MOD) dp[i] -= MOD;
    }
  }
  vector<vector<long long>> M(m, vector<long long>(m, 0));
  for (int i = 0; i < m - 1; ++i) {
    M[i][i + 1] = 1;
  }
  M[m - 1][0] = 1;
  M[m - 1][m - 1] = 1;
  auto Q = pow(M, n);
  for (int i = 0; i < m; ++i) {
    for (int j = 0; j < m; ++j) {
    }
  }
  vector<vector<long long>> b(m, vector<long long>(1, 1));
  Q = mult(Q, b);
  cout << Q[0][0] << endl;
  return 0;
}
