#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007LL;
struct mat {
  long long r, c;
  long long arr[105][105];
  mat() {}
  mat(int a, int b) {
    r = a;
    c = b;
    for (int i = 0; i < a; i++) {
      for (int j = 0; j < b; j++) {
        arr[i][j] = 0;
      }
    }
  }
};
void pr(mat a) {
  for (int i = 0; i < a.r; i++) {
    for (int j = 0; j < a.c; j++) {
      cout << a.arr[i][j] << "  ";
    }
    cout << endl;
  }
}
mat mult(mat a, mat b) {
  mat ans = mat(a.r, b.c);
  assert(a.c == b.r);
  long long i, j, k, now, p, q;
  for (i = 0; i < a.r; i++) {
    for (j = 0; j < b.c; j++) {
      for (k = 0; k < a.c; k++) {
        now = (a.arr[i][k] * b.arr[k][j]) % mod;
        ans.arr[i][j] += now;
        ans.arr[i][j] %= mod;
      }
    }
  }
  return ans;
}
int main() {
  long long n, k, i, j;
  scanf("%lld %lld", &n, &k);
  if (n < k) return !printf("1\n");
  if (n == k) return !printf("2\n");
  mat iden = mat(k, k);
  iden.arr[0][k - 1] = 1;
  for (i = 1; i < k; i++) iden.arr[i][i - 1] = 1;
  iden.arr[0][0] = 1;
  n -= k;
  mat base = mat(k, 1);
  for (i = 0; i < k; i++) base.arr[i][0] = 1;
  base.arr[0][0] = 2;
  n--;
  mat now = iden;
  mat here = iden;
  while (n) {
    if (n % 2) {
      here = mult(here, now);
    }
    n = n / 2LL;
    now = mult(now, now);
  }
  here = mult(here, base);
  printf("%lld\n", here.arr[0][0]);
  return 0;
}
