#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const int MAX_M = 105;
ll n;
int m;
ll tmp[MAX_M][MAX_M], tf[MAX_M][MAX_M], res[MAX_M][MAX_M];
void matmul(ll a[][MAX_M], ll b[][MAX_M]) {
  for (int i = 0; i < m; i++) fill_n(tmp[i], m, 0);
  for (int i = 0; i < m; i++) {
    for (int k = 0; k < m; k++) {
      for (int j = 0; j < m; j++)
        tmp[i][j] = (tmp[i][j] + a[i][k] * b[k][j]) % MOD;
    }
  }
  for (int i = 0; i < m; i++) copy_n(tmp[i], m, a[i]);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n >> m;
  tf[0][0] = tf[0][m - 1] = 1;
  for (int i = 1; i < m; i++) tf[i][i - 1] = 1;
  for (int i = 0; i < m; i++) res[i][i] = 1;
  while (n) {
    if (n & 1) matmul(res, tf);
    matmul(tf, tf);
    n >>= 1;
  }
  cout << accumulate(res[m - 1], res[m - 1] + m, 0LL) % MOD << "\n";
  return 0;
}
