#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;
const long long LINF = 1e17;
const double pi = 3.1415926535897932;
const string endstr = "\n";
template <typename T>
T gcd(T a, T b) {
  return (a == 0) ? b : gcd(b % a, a);
}
template <typename T>
T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
bool p_comp_fs(const pair<long long, long long> p1,
               const pair<long long, long long> p2) {
  return p1.first < p2.first;
};
bool p_comp_fg(const pair<long long, long long> p1,
               const pair<long long, long long> p2) {
  return p1.first > p2.first;
};
bool p_comp_ss(const pair<long long, long long> p1,
               const pair<long long, long long> p2) {
  return p1.second < p2.second;
};
bool p_comp_sg(const pair<long long, long long> p1,
               const pair<long long, long long> p2) {
  return p1.second > p2.second;
};
template <typename T>
vector<T> uniquen(vector<T> vec) {
  vec.erase(unique(vec.begin(), vec.end()), vec.end());
  return vec;
}
const long long mod = 1e9 + 7;
struct Matrix {
  vector<vector<long long> > val;
  Matrix(long long n, long long m, long long x = 0)
      : val(n, vector<long long>(m, x)) {}
  void init(long long n, long long m, long long x = 0) {
    val.assign(n, vector<long long>(m, x));
  }
  long long size() const { return val.size(); }
  inline vector<long long>& operator[](long long i) { return val[i]; }
};
Matrix operator*(Matrix A, Matrix B) {
  long long mat_size = A.size();
  Matrix R(mat_size, mat_size);
  for (long long i = 0; i < mat_size; i++)
    for (long long j = 0; j < mat_size; j++) {
      A[i][j] %= mod;
      B[i][j] %= mod;
    }
  long long modsq = 4 * mod * mod;
  for (long long i = 0; i < mat_size; i++)
    for (long long j = 0; j < mat_size; j++)
      for (long long k = 0; k < mat_size; k++) {
        R[i][j] += A[i][k] * B[k][j];
        if (R[i][j] > modsq) R[i][j] %= mod;
      }
  for (long long i = 0; i < mat_size; i++)
    for (long long j = 0; j < mat_size; j++) R[i][j] %= mod;
  return R;
}
Matrix pow(Matrix A, long long n) {
  Matrix R(A.size(), A.size());
  for (long long 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;
}
long long N, M;
void prepare(Matrix& mat) {
  for (long long i = 0; i < M; i++)
    for (long long j = 0; j < M; j++) {
      if (i == 0) {
        if (j == 0 || j == M - 1) mat[i][j] = 1;
      } else if (i == j + 1) {
        mat[i][j] = 1;
      }
    }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> N >> M;
  auto mat = Matrix(M, M);
  prepare(mat);
  auto matN = pow(mat, N - (M - 1));
  long long ans = 0;
  for (long long i = 0; i < M; i++) ans += matN[0][i];
  cout << ans % mod << endl;
  return 0;
}
