#include <bits/stdc++.h>
using namespace std;
long long INF = 1 << 28;
const double pi = acos(-1.0);
int fx[] = {1, -1, 0, 0};
int fy[] = {0, 0, 1, -1};
int dir[4][2] = {1, 0, -1, 0, 0, -1, 0, 1};
int knight[8][2] = {1, 2, 1, -2, 2, 1, 2, -1, -1, 2, -1, -2, -2, 1, -2, -1};
const long double EPS = 1e-7;
long long gcd(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
bool cmp(int a, int b) { return a < b; }
int on(int mask, int st) { return mask | (1 << st); }
int off(int mask, int st) { return mask & (~(1 << st)); }
bool check(int mask, int st) { return mask & (1 << st); }
long long inf = 1e18;
long long mod = 1e9 + 7;
long long n, k;
long long dp[200000];
long long fun(int pos) {
  if (pos == 0) return 1;
  if (pos < 0) return 0;
  if (dp[pos] != -1) return dp[pos];
  long long ans = 0;
  ans = fun(pos - 1) + fun(pos - k);
  return dp[pos] = ans;
}
struct matrix {
  long long v[101][101];
  int row, col;
};
matrix multiply(matrix a, matrix b) {
  long long sum = 0;
  matrix ans;
  ans.row = a.row;
  ans.col = b.col;
  for (int i = 0; i < ans.row; i++) {
    for (int j = 0; j < ans.col; j++) {
      sum = 0;
      for (int k = 0; k < b.row; k++) {
        sum += a.v[i][k] * b.v[k][j];
        sum %= mod;
      }
      ans.v[i][j] = sum;
    }
  }
  return ans;
}
matrix bigmod(matrix mat, long long p) {
  if (p == 1) return mat;
  if (p % 2 == 0) {
    matrix a = bigmod(mat, p / 2);
    return multiply(a, a);
  } else {
    matrix a = bigmod(mat, p - 1);
    return multiply(mat, a);
  }
}
matrix con, base;
int main(void) {
  memset(dp, -1, sizeof(dp));
  scanf("%lld %lld", &n, &k);
  if (n < k) {
    cout << 1 << endl;
    return 0;
  }
  base.row = k;
  base.col = 1;
  for (int i = 0; i < k; i++) {
    base.v[i][0] = 1;
  }
  con.row = k;
  con.col = k;
  con.v[0][0] = 1;
  for (int i = 1; i < k; i++) {
    con.v[i][i - 1] = 1;
  }
  con.v[0][k - 1] = 1;
  matrix ans = bigmod(con, n - k + 1);
  ans = multiply(ans, base);
  ans = multiply(ans, base);
  cout << ans.v[0][0] << endl;
  return 0;
}
