#include <bits/stdc++.h>
using namespace std;
const unsigned long long MOD = 1e9 + 7;
struct Matrix {
  unsigned long long ma[110][110];
  int n;
  Matrix() {}
  Matrix(int _n) {
    n = _n;
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++) ma[i][j] = 0;
  }
  Matrix operator*(const Matrix &b) const {
    Matrix ret = Matrix(n);
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++)
        for (int k = 0; k < n; k++) {
          ret.ma[i][j] += ma[i][k] * b.ma[k][j];
          ret.ma[i][j] %= MOD;
        }
    return ret;
  }
  void set_one() {
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++) ma[i][j] = (i == j);
  }
};
void Mapow(Matrix &a, Matrix &ans, long long n) {
  ans.set_one();
  while (n) {
    if (n & 1) ans = ans * a;
    a = a * a;
    n >>= 1;
  }
}
int main() {
  long long n;
  int m;
  scanf("%lld%d", &n, &m);
  if (n < m) return 0 * printf("1\n");
  Matrix a(m);
  Matrix ans(m);
  for (int i = 0; i < m; i++)
    for (int j = 0; j < m; j++) a.ma[i][j] = 0;
  for (int i = 1; i < m; i++) a.ma[i][i - 1] = 1;
  a.ma[0][m - 1] = a.ma[m - 1][m - 1] = 1;
  Mapow(a, ans, n);
  unsigned long long res = 0;
  for (int i = 0; i < m; i++) {
    res += ans.ma[i][0];
    if (res >= MOD) res -= MOD;
  }
  printf("%llu\n", res);
}
