#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
void print_matrix(const vector<ll> &a, int m) {
  for (int i = 0; i < m; ++i) {
    for (int j = 0; j < m; ++j) {
      cout << a[i * m + j] << ' ';
    }
    cout << endl;
  }
  cout << endl;
}
vector<ll> mult(const vector<ll> &a, const vector<ll> &b, int m) {
  vector<ll> res(a.size());
  for (int i = 0; i < m; ++i) {
    for (int j = 0; j < m; ++j) {
      for (int k = 0; k < m; ++k) {
        res[i * m + j] += (a[i * m + k] * b[k * m + j]) % MOD;
        res[i * m + j] %= MOD;
      }
    }
  }
  return res;
}
vector<ll> matrix_pow(vector<ll> a, ll n, int m) {
  vector<ll> res = a;
  --n;
  while (n) {
    if (n % 2ll == 0) {
      a = mult(a, a, m);
      n /= 2ll;
    } else {
      res = mult(res, a, m);
      --n;
    }
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n, m;
  cin >> n >> m;
  vector<ll> x(m, 1);
  x[0] = 2;
  if (n <= m) {
    cout << x[m - n] << endl;
    return 0;
  }
  vector<ll> a(m * m);
  a[0] = 1;
  a[m - 1] = 1;
  for (int i = 1; i < m; ++i) {
    a[m * i + i - 1] = 1;
  }
  a = matrix_pow(a, n - m, m);
  ll ans = 0;
  for (int j = 0; j < m; ++j) {
    ans += (a[j] * x[j]) % MOD;
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}
