#include <bits/stdc++.h>
using namespace std;
long long int n, m, mod = 1000000007LL;
vector<vector<long long int> > C;
vector<vector<long long int> > cross(vector<vector<long long int> > A,
                                     vector<vector<long long int> > B) {
  for (int i = 0; i < m; ++i) {
    for (int j = 0; j < m; ++j) {
      C[i][j] = 0;
      for (int k = 0; k < m; ++k) {
        C[i][j] += A[i][k] * B[k][j];
        if (C[i][j] >= 0x3f3f3f3f3f3f3f3f) C[i][j] %= mod;
      }
      if (C[i][j] >= mod) C[i][j] %= mod;
    }
  }
  return C;
}
long long int mxp(vector<vector<long long int> > base, long long int xp) {
  vector<vector<long long int> > ans(m, vector<long long int>(m));
  for (int i = 0; i < m; ++i) ans[i][i] = 1;
  while (xp) {
    if (xp & 1L) ans = cross(base, ans);
    base = cross(base, base);
    xp >>= 1LL;
  }
  long long int sum = 0;
  for (int i = 0; i < m; ++i) {
    sum += ans[0][i];
    if (sum >= mod) sum -= mod;
  }
  return sum;
}
long long int sol() {
  if (n < m) return 1;
  vector<vector<long long int> > mt(m, vector<long long int>(m));
  mt[0][0] = mt[0][m - 1] = 1;
  for (int i = 1; i < m; ++i) mt[i][i - 1] = 1;
  return mxp(mt, n - m + 1);
}
int main() {
  scanf("%lld %lld", &n, &m);
  C.assign(m, vector<long long int>(m));
  printf("%lld\n", sol());
}
