#include <bits/stdc++.h>
using namespace std;
const int NUM = 105, mod = 1e9 + 7;
int MAXN = NUM;
struct Matrix {
  long long a[NUM][NUM];
  void init() {
    memset(a, 0, sizeof(a));
    for (int i = 0; i < MAXN; i++) a[i][i] = 1;
  }
};
Matrix mul(Matrix x, Matrix y) {
  Matrix ret;
  for (int i = 0; i < MAXN; i++) {
    for (int j = 0; j < MAXN; j++) {
      ret.a[i][j] = 0;
      for (int k = 0; k < MAXN; k++) {
        ret.a[i][j] += x.a[i][k] * y.a[k][j] % mod;
        ret.a[i][j] %= mod;
      }
    }
  }
  return ret;
}
Matrix pow(Matrix a, long long n) {
  Matrix ans;
  ans.init();
  while (n > 0) {
    if (n & 1) ans = mul(ans, a);
    n >>= 1;
    a = mul(a, a);
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n, m;
  cin >> n >> m;
  Matrix A, ans;
  ans.a[0][0] = ans.a[0][m - 1] = 1;
  for (int i = 1; i < m; ++i) {
    ans.a[i][i - 1] = 1;
  }
  A = pow(ans, n);
  cout << A.a[0][0] << endl;
  return 0;
}
