#include <bits/stdc++.h>
using namespace std;
class Matrix {
 public:
  int n;
  long long **a;
  Matrix() { n = 0; }
  Matrix(int n) {
    this->n = n;
    a = new long long *[n];
    for (int i = 0; i < n; i++) {
      a[i] = new long long[n];
      for (int j = 0; j < n; j++) a[i][j] = 0;
    }
  }
  Matrix &operator*(Matrix m) {
    long long **b = new long long *[n];
    for (int i = 0; i < n; i++) b[i] = new long long[n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        b[i][j] = 0;
        for (int k = 0; k < n; k++)
          b[i][j] = (b[i][j] + this->a[i][k] * m.a[k][j]) % 1000000007;
      }
    }
    this->a = b;
    return *this;
  }
};
Matrix bp(Matrix m, long long d) {
  if (d == 1) return m;
  if (d % 2 == 0) {
    Matrix m1 = bp(m, d / 2);
    return m1 * m1;
  }
  Matrix m1(m.n);
  for (int i = 0; i < m.n; i++)
    for (int j = 0; j < m.n; j++) m1.a[i][j] = m.a[i][j];
  return m1 * bp(m, d - 1);
}
long long n, m;
long long f[1000];
Matrix M(1);
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> m;
  for (int i = 1; i <= 2 * m - 1; i++) f[i] = max(0ll, i - m + 1) + 1;
  if (n < 2 * m) {
    cout << f[n] << endl;
    return 0;
  }
  M = Matrix(m);
  M.a[0][0] = 1;
  M.a[m - 1][0] = 1;
  for (int i = 1; i <= m - 1; i++) M.a[i - 1][i] = 1;
  long long d = n - m;
  M = bp(M, d);
  long long fn = 0;
  for (int i = 1; i <= m; i++) fn = (fn + f[i] * M.a[m - i][0]) % 1000000007;
  cout << fn << endl;
  return 0;
}
