#include <bits/stdc++.h>
using namespace std;
const int N = 1e2 + 5;
const int mod = 1e9 + 7;
int m;
long long n;
struct Matrix {
  long long a[N][N];
  Matrix() { memset(a, 0, sizeof(a)); }
  Matrix operator*(const Matrix &rhs) const {
    Matrix ans;
    for (int k = 0; k < m; k++)
      for (int i = 0; i < m; i++)
        for (int j = 0; j < m; j++)
          (ans.a[i][j] += (1ll * a[i][k] * rhs.a[k][j]) % mod) %= mod;
    return ans;
  }
} base;
int a[N][N];
Matrix bigmod(Matrix a, long long b) {
  Matrix res;
  for (int i = 0; i < m; i++) {
    res.a[i][i] = 1;
  }
  while (b) {
    if (b & 1) {
      res = res * a;
    }
    b >>= 1;
    a = a * a;
  }
  return res;
}
int main() {
  scanf("%lld %d", &n, &m);
  if (n < m) {
    return puts("1"), 0;
  }
  a[0][0] = a[0][m - 1] = 1;
  for (int i = 1; i < m; i++) {
    a[i][i - 1] = 1;
  }
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < m; j++) {
      base.a[i][j] = a[i][j];
    }
  }
  Matrix ans;
  for (int i = 0; i < m; i++) {
    ans.a[i][0] = 1;
  }
  ans = bigmod(base, n - m + 1) * ans;
  cout << ans.a[0][0];
}
