#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
vector<vector<long long> > operator+(vector<vector<long long> > a,
                                     vector<vector<long long> > b) {
  long long n = (long long)a.size();
  long long m = (long long)a[0].size();
  vector<vector<long long> > c;
  c.resize(n);
  for (long long i = 0; i < n; i++) {
    c[i].resize(m);
    for (long long j = 0; j < m; j++) {
      c[i][j] = a[i][j] + b[i][j];
      c[i][j] %= mod;
    }
  }
  return c;
}
vector<vector<long long> > operator*(vector<vector<long long> > a,
                                     vector<vector<long long> > b) {
  long long n = (long long)a.size();
  long long m = (long long)b.size();
  long long p = (long long)b[0].size();
  vector<vector<long long> > c(n, vector<long long>(p));
  long long col[m];
  for (long long j = 0; j < p; j++) {
    for (long long k = 0; k < m; k++) col[k] = b[k][j];
    for (long long i = 0; i < n; i++) {
      long long s = 0;
      for (long long k = 0; k < m; k++) {
        s += (a[i][k] * col[k]) % mod;
        s %= mod;
      }
      c[i][j] = s;
    }
  }
  return c;
}
vector<vector<long long> > operator*(double k, vector<vector<long long> > a) {
  long long n = (long long)a.size();
  long long m = (long long)a[0].size();
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      a[i][j] *= k;
      a[i][j] %= mod;
    }
  }
  return a;
}
vector<vector<long long> > operator-(vector<vector<long long> > a,
                                     vector<vector<long long> > b) {
  return a + ((-1) * b);
}
void printmatrix(vector<vector<long long> >& a) {
  long long n = (long long)a.size();
  long long m = (long long)a[0].size();
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      cout << a[i][j] << " ";
    }
    cout << "\n";
  }
}
vector<vector<long long> > id(long long n) {
  vector<vector<long long> > c(n, vector<long long>(n));
  for (long long i = 0; i < n; i++) c[i][i] = 1;
  return c;
}
vector<vector<long long> > matrixExp(vector<vector<long long> > a,
                                     long long n) {
  if (n == 0) return id(a.size());
  vector<vector<long long> > c = matrixExp(a, n / 2);
  c = c * c;
  if (n % 2 != 0) c = c * a;
  return c;
}
long long n, m;
void solve() {
  cin >> n >> m;
  if (n < m) {
    cout << "1\n";
    return;
  }
  vector<vector<long long> > rec(m, vector<long long>(m, 0));
  rec[0][0] = rec[0][m - 1] = 1;
  for (long long i = 1; i < m; i++) rec[i][i - 1] = 1;
  vector<vector<long long> > ini(m, vector<long long>(1, 1));
  ini[0][0]++;
  vector<vector<long long> > ans = matrixExp(rec, n - m);
  ans = ans * ini;
  cout << ans[0][0];
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  solve();
}
