#include <bits/stdc++.h>
using namespace std;
const long long mxn = 155;
const long long mod = 1e9 + 7;
const long long N = 155;
long long n;
struct mat {
  long long a[105][105];
  mat() { memset(a, 0, sizeof(a)); }
} t;
mat mul(mat x, mat y) {
  mat c;
  for (long long i = 1; i <= n; i++)
    for (long long j = 1; j <= n; j++)
      for (long long k = 1; k <= n; k++)
        c.a[i][j] = (c.a[i][j] + x.a[i][k] * y.a[k][j]) % mod;
  return c;
}
mat pw(mat a, long long b) {
  mat res = a;
  b--;
  while (b) {
    if (b & 1) res = mul(res, a);
    a = mul(a, a);
    b >>= 1;
  }
  return res;
}
signed main() {
  long long m;
  cin >> m >> n;
  for (long long i = 1; i < n; i++) t.a[i][i + 1] = 1;
  t.a[n][1] = t.a[n][n] = 1;
  t = pw(t, m);
  cout << t.a[n][n];
  return 0;
}
