#include <bits/stdc++.h>
using namespace std;
const long long N = 105;
long long add(long long x, long long y) {
  x += y;
  return x >= 1000000007 ? x - 1000000007 : x;
}
long long mul(long long x, long long y) {
  return (long long)x * y % 1000000007;
}
struct Matrix {
  long long a[N][N];
  Matrix() {}
};
Matrix operator*(Matrix a, Matrix b) {
  Matrix ans;
  for (long long i = 1; i < N; i++) {
    for (long long j = 1; j < N; j++) {
      ans.a[i][j] = 0;
      for (long long k = 1; k < N; k++) {
        ans.a[i][j] = add(ans.a[i][j], mul(a.a[i][k], b.a[k][j]));
      }
    }
  }
  return ans;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, m;
  cin >> n >> m;
  Matrix dp;
  dp.a[1][1] = 1;
  dp.a[1][m] = 1;
  for (long long i = 1; i <= m - 1; i++) dp.a[i + 1][i] = 1;
  Matrix ans;
  for (long long i = 1; i <= m; i++) ans.a[i][i] = 1;
  while (n > 0) {
    if (n & 1) ans = ans * dp;
    dp = dp * dp;
    n >>= 1;
  }
  cout << ans.a[1][1];
}
