#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long n, m;
inline void matmul(const vector<vector<int>>& ma, const vector<vector<int>>& mb,
                   vector<vector<int>>& res) {
  for (int i = 0; i < (m); i++)
    for (int j = 0; j < (m); j++) {
      res[i][j] = 0;
      for (int k = 0; k < (m); k++)
        res[i][j] = (res[i][j] + ma[i][k] * 1LL * mb[k][j]) % mod;
    }
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  vector<vector<int>> M(m, vector<int>(m));
  for (int i = 0; i < (m - 1); i++) M[i + 1][i] = 1;
  M[0][0] = 1;
  M[0][m - 1] = 1;
  vector<vector<int>> res(m, vector<int>(m));
  vector<vector<int>> a(m, vector<int>(m));
  for (int i = 0; i < (m); i++) a[i][i] = res[i][i] = 1;
  while (n) {
    if (n & 1) {
      matmul(M, res, a);
      swap(a, res);
    }
    n /= 2;
    matmul(M, M, a);
    swap(a, M);
  }
  cout << res[0][0] << '\n';
}
