#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const int MAXN = 123;
long long n;
int m;
struct Mat {
  long long X[MAXN][MAXN];
  Mat() { memset(X, 0, sizeof X); }
  Mat operator*(Mat Y) {
    Mat mult;
    for (int i = 0; i < m; ++i) {
      for (int j = 0; j < m; ++j) {
        for (int k = 0; k < m; ++k) {
          mult.X[i][j] += ((X[i][k] % MOD) * (Y.X[k][j] % MOD)) % MOD;
          mult.X[i][j] = mult.X[i][j] % MOD;
        }
      }
    }
    return mult;
  }
};
Mat fexp(Mat b, long long e) {
  Mat s;
  for (int i = 0; i < m; ++i) s.X[i][i] = 1;
  while (e) {
    if (e & 1) s = s * b;
    e >>= 1;
    b = b * b;
  }
  return s;
}
long long solve() {
  Mat F;
  for (int i = 0; i + 1 < m; ++i) F.X[i][i + 1] = 1;
  F.X[m - 1][0] = F.X[m - 1][m - 1] = 1;
  Mat Y = fexp(F, n);
  long long ans = 0;
  for (int i = 0; i < m; ++i) ans += Y.X[0][i];
  return ans % MOD;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m;
  cout << solve() << '\n';
  return 0;
}
