#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
long long n, m;
struct mat {
  long long num[104][104];
};
void print_matrix(mat a) {
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < m; j++) cout << a.num[i][j] << " ";
    cout << "\n";
  }
  return;
}
mat a, t;
mat mul(mat a, mat b) {
  mat res;
  memset(res.num, 0, sizeof(res.num));
  for (int i = 0; i < m; i++)
    for (int j = 0; j < m; j++)
      for (int k = 0; k < m; k++) {
        res.num[i][j] += a.num[i][k] * b.num[k][j];
        res.num[i][j] %= MOD;
      }
  return res;
}
long long pow(mat a) {
  for (; n; n >>= 1) {
    if (n & 1) t = mul(a, t);
    a = mul(a, a);
  }
  return t.num[0][0];
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m - 1; i++) a.num[i + 1][i] = 1;
  a.num[0][0] = 1;
  a.num[0][m - 1] = 1;
  for (int i = 0; i < m; i++) t.num[i][i] = 1;
  cout << pow(a);
}
