#include <bits/stdc++.h>
using namespace std;
void reads(long long &x) {
  int fx = 1;
  x = 0;
  char s = getchar();
  while (s < '0' || s > '9') {
    if (s == '-') fx = -1;
    s = getchar();
  }
  while (s >= '0' && s <= '9') {
    x = (x << 3) + (x << 1) + (s - '0');
    s = getchar();
  }
  x = x * fx;
}
const int mod = 1e9 + 7;
struct mat {
  long long m[109][109];
  mat(long long x = 0) {
    memset(m, 0, sizeof m);
    for (long long i = 1; i < 109; i++) m[i][i] = x;
  }
  friend mat operator*(mat a, mat b) {
    mat cnt;
    for (long long i = 1; i < 109; i++)
      for (long long j = 1; j < 109; j++)
        for (long long k = 1; k < 109; k++)
          cnt.m[i][j] = (cnt.m[i][j] + 1LL * a.m[i][k] * b.m[k][j] % mod) % mod;
    return cnt;
  }
};
int main() {
  long long n, m;
  cin >> n >> m;
  mat a, b;
  a.m[1][1] = 1;
  for (long long i = 1; i <= m - 1; i++) b.m[i][i + 1] = 1;
  b.m[1][1] = 1;
  b.m[m][1] = 1;
  while (n) {
    if (n & 1) a = a * b;
    b = b * b;
    n >>= 1;
  }
  cout << a.m[1][1] << endl;
}
