#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int m;
vector<vector<long long> > mul(vector<vector<long long> > &a,
                               vector<vector<long long> > &b) {
  vector<vector<long long> > c(a.size(), vector<long long>(b[0].size()));
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < m; j++) {
      for (int k = 0; k < m; k++) {
        c[i][j] += a[i][k] * b[k][j];
        c[i][j] %= mod;
      }
    }
  }
  return c;
}
vector<vector<long long> > pow(vector<vector<long long> > a, long long n) {
  vector<vector<long long> > res(a.size(), vector<long long>(a.size()));
  for (int i = 0; i < m; i++) res[i][0] = 1;
  while (n) {
    if (n & 1) res = mul(res, a);
    a = mul(a, a);
    n /= 2;
  }
  return res;
}
long long solve(long long n) {
  vector<vector<long long> > a(m, vector<long long>(m));
  a[0][m - 1] = a[0][0] = 1;
  for (int i = 1; i < m; i++) a[i][i - 1] = 1;
  a = pow(a, n);
  return a[0][0];
}
int main() {
  long long n;
  cin >> n >> m;
  cout << solve(n) << endl;
}
