#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long f = 1, x = 0;
  char s = getchar();
  while (s < '0' || s > '9') {
    if (s == '-') f = -1;
    s = getchar();
  }
  while (s >= '0' && s <= '9') {
    x = x * 10 + (s - '0');
    s = getchar();
  }
  return x * f;
}
const int jzm = 1000000007;
int n, m, i, j, s, o, k;
long long N;
struct mat {
  int n, m;
  int s[105][105];
  mat() {
    n = m = 0;
    memset(s, 0, sizeof(s));
  }
} A, B;
mat operator*(mat a, mat b) {
  mat c;
  c.n = a.n;
  c.m = b.m;
  for (int i = 1; i <= c.n; i++) {
    for (int k = 1; k <= a.m; k++) {
      if (a.s[i][k])
        for (int j = 1; j <= c.m; j++) {
          (c.s[i][j] += (a.s[i][k] * 1ll * b.s[k][j] % jzm)) %= jzm;
        }
    }
  }
  return c;
}
mat qkpow(mat a, long long b) {
  mat res;
  res.n = res.m = a.n;
  for (int i = 1; i <= a.n; i++) res.s[i][i] = 1;
  while (b > 0) {
    if (b & 1) res = res * a;
    a = a * a;
    b >>= 1;
  }
  return res;
}
int main() {
  N = read();
  m = read();
  A.n = 1;
  A.m = B.n = B.m = m;
  A.s[1][m] = 1;
  for (int i = 1; i < m; i++) {
    B.s[i + 1][i] = 1;
  }
  B.s[m][m] = 1;
  B.s[1][m] = 1;
  mat C = A * qkpow(B, N);
  printf("%d\n", C.s[1][m]);
  return 0;
}
