#include <bits/stdc++.h>
const long long int MOD = 1e9 + 7;
const long long int INF = 1011111111;
const long long int LLINF = 1000111000111000111LL;
const long double EPS = 1e-10;
const long double PI = 3.14159265358979323;
using namespace std;
inline long long int add(long long int a, long long int b) {
  a += b;
  if (a >= MOD) a -= MOD;
  return a;
}
inline long long int sub(long long int a, long long int b) {
  a -= b;
  if (a < 0) a += MOD;
  return a;
}
inline long long int mul(long long int a, long long int b) {
  return (a * 1ll * b) % MOD;
}
long long int power(long long int base, long long int exponent) {
  long long int ans = 1;
  while (exponent != 0) {
    if (exponent & 1) ans = (1LL * ans * base);
    base = (1LL * base * base);
    exponent >>= 1;
  }
  return ans;
}
long long int K;
vector<vector<long long int> > multiply(vector<vector<long long int> > A,
                                        vector<vector<long long int> > B) {
  long long int i, j, k;
  vector<vector<long long int> > C(K, vector<long long int>(K, 0));
  for (i = 0; i < K; i++) {
    for (j = 0; j < K; j++) {
      for (k = 0; k < K; k++) {
        C[i][j] += (A[i][k] * B[k][j]) % MOD;
        C[i][j] %= MOD;
      }
    }
  }
  return C;
}
vector<vector<long long int> > power(vector<vector<long long int> > A,
                                     long long int n) {
  if (n == 1) return A;
  vector<vector<long long int> > X = power(multiply(A, A), n / 2);
  if (n & 1ll) X = multiply(X, A);
  return X;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n, m, i, j, k;
  cin >> n >> m;
  K = m;
  vector<vector<long long int> > T(K, vector<long long int>(K, 0));
  T[0][0] = 1;
  T[0][K - 1] = 1;
  for (i = 1; i < K; i++) T[i][i - 1] = 1;
  long long int ans = 0;
  if (n - (m - 1) <= 0) return cout << 1, 0;
  T = power(T, n - (m - 1));
  for (i = 0; i < K; i++) {
    ans += T[0][i];
    ans %= MOD;
  }
  cout << ans;
  cerr << '\n'
       << "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms"
       << '\n';
}
