#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6;
const int mod = 1e9 + 7;
vector<vector<long long>> operator*(const vector<vector<long long>>& a,
                                    const vector<vector<long long>>& b) {
  vector<vector<long long>> result = vector<vector<long long>>(
      (int(a.size())), vector<long long>((int(b[0].size())), 0));
  for (int i = 0; i < ((int(a.size()))); ++i)
    for (int j = 0; j < ((int(b[0].size()))); ++j)
      for (int k = 0; k < ((int(a[0].size()))); ++k)
        result[i][j] = (result[i][j] + a[i][k] * b[k][j]) % mod;
  return result;
}
vector<vector<long long>> Matrandonvi(int n) {
  vector<vector<long long>> result =
      vector<vector<long long>>(n, vector<long long>(n, 0));
  for (int i = 0; i < n; ++i) {
    result[i][i] = 1;
  }
  return result;
}
vector<vector<long long>> Getmatrix(int n) {
  vector<vector<long long>> result =
      vector<vector<long long>>(n, vector<long long>(n, 0));
  result[0][0] = result[0][n - 1] = 1;
  for (int i = 1; i < n; ++i) result[i][i - 1] = 1;
  return result;
}
vector<vector<long long>> solve(int n, long long k) {
  vector<vector<long long>> result = Matrandonvi(n);
  vector<vector<long long>> a = Getmatrix(n);
  while (k != 0) {
    if ((k & 1)) result = result * a;
    a = a * a;
    k /= 2;
  }
  return result;
}
int m;
long long n;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  if (fopen("TEST"
            ".INP",
            "r"))
    freopen(
        "TEST"
        ".INP",
        "r", stdin),
        freopen(
            "TEST"
            ".OUT",
            "w", stdout);
  cin >> n >> m;
  cout << solve(m, n)[0][0];
}
