#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
struct Matrix {
  int N = 100;
  long long a[100][100];
  Matrix() {}
  void one() {
    for (int i = 0; i < N; i++)
      for (int j = 0; j < N; j++) a[i][j] = (i == j);
  }
  Matrix operator*(Matrix B) {
    Matrix ret, A = *this;
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        ret.a[i][j] = 0;
        for (int k = 0; k < N; k++)
          ret.a[i][j] = (ret.a[i][j] + A.a[i][k] * B.a[k][j] % mod) % mod;
      }
    }
    return ret;
  }
  Matrix pwr(long long K) {
    Matrix ret, A = *this;
    ret.one();
    while (K > 0) {
      if (K & 1) ret = ret * A;
      A = A * A;
      K >>= 1;
    }
    return ret;
  }
};
long long n, m;
int main() {
  cin >> n >> m;
  Matrix A;
  A.a[0][0] = A.a[0][m - 1] = 1;
  for (int i = 0; i < m - 1; i++) A.a[i + 1][i] = 1;
  A = A.pwr(n - (m - 1));
  long long ans = 0;
  for (int i = 0; i < m; i++) {
    ans += A.a[0][i];
    ans = ans % mod;
  }
  cout << ans;
  return 0;
}
