#include <bits/stdc++.h>
using namespace std;
const int maxn = 100001;
int n;
template <typename T, int N = 1>
struct Matrix {
  Matrix(int f = 0) : n(sizeof(data[0]) / sizeof(data[0][0])) {
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++) data[i][j] = T(0);
    if (f)
      for (int i = 0; i < n; data[i][i] = T(1), ++i) {
      }
  }
  Matrix operator*(const Matrix& other) const {
    Matrix<T, N> ret;
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++)
        for (int k = 0; k < n; k++)
          ret.data[i][j] =
              (ret.data[i][j] + data[i][k] * other.data[k][j] % 1000000007) %
              1000000007;
    return ret;
  }
  Matrix operator+(const Matrix& other) const {
    Matrix<T, N> ret;
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++)
        ret.data[i][j] = (data[i][j] + other.data[i][j]) % 1000000007;
    return ret;
  }
  Matrix& operator%(const long long mod) { return *this; }
  T data[N][N];
  int n;
};
template <typename T>
T mul(T a, long long n, long long mod) {
  T ret(1);
  for (; n; n >>= 1) {
    ret = ret * (n & 1 ? a : T(1)) % mod;
    a = a * a % mod;
  }
  return ret;
}
const long long modulu[2][2] = {{1, 1}, {1, 0}};
void output() {
  int m;
  for (long long n; cin >> n >> m && n + 1;) {
    if (n < m) {
      cout << 1 << endl;
      continue;
    }
    Matrix<long long, 101> a;
    a.data[0][m - 1] = a.data[0][0] = 1;
    for (int i = 1; i < m; i++) a.data[i][i - 1] = 1;
    long long mod = 1000000007;
    Matrix<long long, 101> ans = mul(a, n - m + 1, mod);
    long long an = 0;
    for (int i = 0; i < m; i++) {
      an = (an + ans.data[0][i]) % mod;
    }
    cout << an << endl;
  }
  return;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  output();
}
