#include <bits/stdc++.h>
using namespace std;
const long long M = 100;
long long sz;
struct Mat {
  long long m[M][M];
  Mat() { memset(m, 0, sizeof m); }
  void eye() {
    for (long long i = 0; i < sz; i++) m[i][i] = 1;
  }
  Mat operator*(const Mat &a) const {
    Mat r;
    for (long long i = 0; i < sz; i++)
      for (long long j = 0; j < sz; j++)
        for (long long k = 0; k < sz; k++)
          r.m[i][j] = (r.m[i][j] + m[i][k] * 1ll * a.m[k][j]) % 1000000007;
    return r;
  }
};
long long modexpo(long long n) {
  Mat a, r;
  r.eye();
  a.m[0][0] = a.m[0][sz - 1] = 1;
  for (long long i = 0; i < sz; i++) a.m[i][i - 1] = 1;
  while (n) {
    if (n % 2) r = r * a;
    n = n / 2;
    a = a * a;
  }
  return r.m[0][0];
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n;
  cin >> n >> sz;
  if (n < sz) {
    cout << 1;
  } else
    cout << modexpo(n);
  return 0;
}
