#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
ll add_mod(ll a, ll b) { return (((a + b) % MOD) + MOD) % MOD; }
ll multiply_mod(ll a, ll b) { return (((a * b) % MOD) + MOD) % MOD; }
struct Matrix {
  const static int N = 100;
  int n;
  long long v[N][N];
  Matrix(int _n) : n(_n) {
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++) v[i][j] = 0;
  }
  Matrix operator*(const Matrix &o) const {
    Matrix res(n);
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++)
        for (int k = 0; k < n; k++)
          res.v[i][j] = add_mod(res.v[i][j], multiply_mod(v[i][k], o.v[k][j]));
    return res;
  }
  static Matrix getIdentity(int n) {
    Matrix res(n);
    for (int i = 0; i < n; i++) res.v[i][i] = 1;
    return res;
  }
  Matrix operator^(long long k) const {
    Matrix res = Matrix ::getIdentity(n);
    Matrix a = *this;
    while (k) {
      if (k & 1) res = res * a;
      a = a * a;
      k /= 2;
    }
    return res;
  }
};
const int MAXM = 100;
const ll MAXN = 1e18;
int main() {
  ll n, m;
  cin >> n >> m;
  Matrix rec(m);
  rec.v[0][0] = 1;
  rec.v[0][m - 1] = 1;
  for (int i = 1; i < m; i++) {
    rec.v[i][i - 1] = 1;
  }
  rec = rec ^ n;
  cout << rec.v[0][0] << '\n';
  return 0;
}
