#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Matrix = vector<vector<long long>>;
long long constexpr MOD = 1000000007;
long long mod(long long x) { return x % MOD; }
Matrix mul(Matrix& a, Matrix& b, long long n) {
  Matrix c = vector<vector<long long>>(n + 1, vector<long long>(n + 1));
  for (long long i = 1; i <= n; ++i)
    for (long long j = 1; j <= n; ++j)
      for (long long k = 1; k <= n; ++k) {
        c[i][j] += mod(a[i][k] * b[k][j]);
        c[i][j] = mod(c[i][j]);
      }
  return c;
}
Matrix matpow(Matrix& base, long long n, long long exp) {
  Matrix res = vector<vector<long long>>(n + 1, vector<long long>(n + 1));
  for (long long i = 1; i <= n; ++i) res[i][i] = 1;
  while (exp > 0) {
    if (exp & 1) res = mul(res, base, n);
    base = mul(base, base, n);
    exp >>= 1;
  }
  return res;
}
ll mpow(ll base, ll exp) {
  base = mod(base);
  ll res = 1;
  while (exp > 0) {
    if (exp & 1) res = mod(res * base);
    base = mod(base * base);
    exp >>= 1;
  }
  return res;
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long n, m;
  cin >> n >> m;
  if (n < m) {
    cout << 1 << endl;
    return 0;
  }
  Matrix t = vector<vector<long long>>(m + 1, vector<long long>(m + 1));
  for (long long i = 1; i <= m; ++i) {
    for (long long j = 1; j <= m; ++j) {
      t[i][j] = (i == 1 && (j == 1 || j == m)) || (j == i - 1);
    }
  }
  Matrix res = matpow(t, m, n - m + 1);
  long long ans = 0;
  for (long long j = 1; j <= m; ++j) {
    ans += res[1][j];
    if (ans >= MOD) ans -= MOD;
  }
  cout << ans << endl;
}
