#include <bits/stdc++.h>
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1 << 28;
constexpr long long mod = 1000000007LL;
using namespace std;
struct mint {
  long long x;
  mint(long long x = 0) : x((x % mod + mod) % mod) {}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(long long t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
};
const int MatrixSize = 100;
using Matrix = array<array<mint, MatrixSize>, MatrixSize>;
Matrix operator*(Matrix& A, Matrix& B) {
  Matrix R = {{}};
  for (int i = 0; i < A.size(); ++i)
    for (int j = 0; j < B[0].size(); ++j)
      for (int k = 0; k < B.size(); ++k)
        R[i][j] = (R[i][j] + A[i][k] * B[k][j]);
  return R;
}
Matrix modpow(Matrix A, long long n) {
  Matrix R = {{}};
  for (int i = 0; i < A.size(); ++i) R[i][i] = 1;
  while (n > 0) {
    if (n & 1) R = R * A;
    A = A * A;
    n >>= 1;
  }
  return R;
}
int main() {
  long long N, M;
  scanf("%lld %lld", &N, &M);
  if (N < M) {
    puts("1");
    return 0;
  }
  Matrix mat = {{}};
  vector<long long> ini(M, 1);
  for (long long i = 1; i < M; i++) {
    mat[i][i - 1] = 1;
  }
  mat[0][M - 1] = 1;
  mat[0][0] = 1;
  mat = modpow(mat, N - M + 1);
  mint res = 0;
  for (int i = 0; i < M; i++) (res += mat[0][i]);
  cout << res.x << endl;
  return 0;
}
