#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<long long>;
using pii = pair<long long, long long>;
const signed INF_ = 1001001001;
const long long INF = 1001001001001001001LL;
const long long DX[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0},
                DY[9] = {-1, 0, 1, 0, -1, 1, 1, -1, 0};
template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  for (auto i = (begin(v)); i != (end(v)); ++i)
    os << *i << (i == end(v) - 1 ? "" : " ");
  return os;
}
template <class T>
istream &operator>>(istream &is, vector<T> &v) {
  for (auto i = (begin(v)); i != (end(v)); ++i) is >> *i;
  return is;
}
template <class T, class U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.first >> p.second;
  return is;
}
template <class T, class U>
bool chmax(T &a, const U &b) {
  return a < b ? a = b, 1 : 0;
}
template <class T, class U>
bool chmin(T &a, const U &b) {
  return a > b ? a = b, 1 : 0;
}
template <class T>
void PSUM(T &c) {
  partial_sum(begin(c), end(c), begin(c));
}
template <class T>
using heap = priority_queue<T, vector<T>, greater<T>>;
struct before_main_function {
  before_main_function() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(15) << fixed;
  }
} before_main_function;
template <class SR>
struct Matrix {
  using T = typename SR::T;
  vector<vector<T>> data;
  Matrix() : Matrix(1, 1, SR::zero()) {}
  Matrix(vector<vector<T>> &&A) : data(A) {}
  Matrix(long long r, long long c, T fill) : data(r, vector<T>(c, fill)) {}
  long long rows() const { return data.size(); }
  long long cols() const { return data[0].size(); }
  static Matrix<SR> multiple(const Matrix<SR> &A, const Matrix<SR> &B) {
    assert(A.cols() == B.rows());
    Matrix<SR> ret(A.rows(), B.cols(), SR::zero());
    for (long long i = 0; i < A.rows(); ++i) {
      for (long long j = 0; j < B.cols(); ++j) {
        T tmp = SR::zero();
        for (long long k = 0; k < A.cols(); ++k) {
          T p = SR::mul(A.data[i][k], B.data[k][j]);
          tmp = SR::add(tmp, p);
        }
        ret.data[i][j] = tmp;
      }
    }
    return ret;
  }
  static Matrix<SR> pow(Matrix<SR> A, long long k) {
    assert(A.rows() == A.cols());
    long long n = A.rows();
    Matrix<SR> ret(n, n, SR::zero());
    for (long long i = 0; i < n; ++i) ret.data[i][i] = SR::identity();
    while (k > 0) {
      if (k & 1) ret = Matrix<SR>::multiple(ret, A);
      A = Matrix<SR>::multiple(A, A);
      k >>= 1;
    }
    return ret;
  }
  Matrix<SR> operator*(const Matrix<SR> &r) {
    return Matrix<SR>::multiple(*this, r);
  }
  Matrix<SR> &operator*=(const Matrix<SR> &r) { return *this = *this * r; }
  Matrix<SR> operator^(long long k) { return Matrix<SR>::pow(*this, k); }
  Matrix<SR> &operator^=(long long k) { return *this = *this ^ k; }
};
struct SemiRing {
  static const long long MOD = 1e9 + 7;
  using T = long long;
  static T add(const T &a, const T &b) { return (a + b) % MOD; }
  static T mul(const T &a, const T &b) { return a * b % MOD; }
  static T zero() { return 0; }
  static T identity() { return 1; }
};
signed main() {
  long long N, M;
  cin >> N >> M;
  if (N < M) {
    cout << 1 << endl;
    return 0;
  }
  vector<vector<long long>> A(M, vector<long long>(M, 0));
  for (long long i = 0, ilen = (long long)(M - 1); i < ilen; ++i) {
    A[i][i + 1] = 1;
  }
  A[M - 1][0] = A[M - 1][M - 1] = 1;
  Matrix<SemiRing> a(move(A));
  long long p = N - M + 1;
  a ^= p;
  vector<vector<long long>> V(M, vector<long long>(1, 1));
  auto v = Matrix<SemiRing>(move(V));
  auto r = a * v;
  cout << r.data[M - 1][0] << endl;
  return (0 ^ 0 ^ 0);
}
