#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
const long long longinf = 1LL << 60;
const long long mod = 1e9 + 7;
template <typename T>
struct Matrix {
  int h, w;
  vector<T> a;
  Matrix(int n_ = 0) : h(n_), w(n_), a(n_ * n_) {}
  Matrix(int n_, int m_) : h(n_), w(m_), a(n_ * m_) {}
  Matrix(int n_, int m_, vector<T> a_) : h(n_), w(m_), a(a_) {}
  T& get(int r, int c) { return a[r * w + c]; }
  T get(int r, int c) const { return a[r * w + c]; }
  Matrix& operator+=(const Matrix& m) {
    assert(h == m.h && w == m.w);
    for (int i = 0; i < w * h; ++i) a[i] += m.a[i];
  }
  Matrix& operator-=(const Matrix& m) {
    assert(h == m.h && w == m.w);
    for (int i = 0; i < w * h; ++i) a[i] -= m.a[i];
  }
  Matrix& operator*=(const Matrix& m) {
    assert(w == m.h);
    Matrix ret(h, m.w);
    for (int i = 0; i < h; ++i) {
      for (int j = 0; j < m.w; ++j) {
        for (int k = 0; k < w; ++k) {
          ret.a[i * m.w + j] += a[i * w + k] * m.a[k * m.w + j] % mod;
        }
        ret.a[i * m.w + j] %= mod;
      }
    }
    return (*this) = ret;
  }
  Matrix operator+(const Matrix& m) const { return Matrix(*this) += m; }
  Matrix operator-(const Matrix& m) const { return Matrix(*this) -= m; }
  Matrix operator*(const Matrix& m) const { return Matrix(*this) *= m; }
};
Matrix<long long> matpow(Matrix<long long> a, long long n) {
  assert(a.h == a.w);
  Matrix<long long> ret(a.h);
  for (int i = (int)(0); i < (int)(a.h); ++i) ret.get(i, i) = 1;
  while (n) {
    if (n & 1) ret = ret * a;
    a = a * a;
    n >>= 1;
  }
  return ret;
}
int main() {
  long long n, m;
  cin >> n >> m;
  Matrix<long long> A(m);
  for (int i = (int)(0); i < (int)(m - 1); ++i) {
    A.get(i + 1, i) = 1;
  }
  A.get(0, 0) = 1;
  A.get(0, m - 1) = 1;
  auto ret = matpow(A, n);
  cout << ret.get(0, 0) % mod << endl;
  return 0;
}
