#include <bits/stdc++.h>
using namespace std;
long long const MOD = 1e9 + 7;
vector<vector<int> > mat_mul(vector<vector<int> > &a, vector<vector<int> > &b) {
  vector<vector<int> > c(a.size(), vector<int>(a[0].size()));
  for (int i = 0; i < a.size(); i++) {
    for (int j = 0; j < a[0].size(); j++) {
      for (int z = 0; z < a[0].size(); z++)
        c[i][j] = (c[i][j] + 1LL * a[i][z] * b[z][j]) % MOD;
    }
  }
  return c;
}
vector<vector<int> > bin_pow(vector<vector<int> > &v, long long p) {
  if (p == 1) return v;
  vector<vector<int> > x = bin_pow(v, p / 2);
  x = mat_mul(x, x);
  if (p % 2) x = mat_mul(x, v);
  return x;
}
int main() {
  long long n, m;
  cin >> n >> m;
  vector<vector<int> > M(m + 1, vector<int>(m + 1));
  for (int i = 0; i < m; i++) M[i + 1][i] = 1;
  M[0][0] = M[0][m - 1] = 1;
  vector<vector<int> > st(m + 1, vector<int>(1));
  st[0][0] = 1;
  if (n == 1)
    cout << 1;
  else {
    vector<vector<int> > A = bin_pow(M, n);
    cout << mat_mul(A, st)[0][0];
  }
  return 0;
}
