#include <bits/stdc++.h>
using namespace std;
long long mult(long long a, long long b, long long p = 1000000007) {
  return ((a % p) * (b % p)) % p;
}
long long add(long long a, long long b, long long p = 1000000007) {
  return (a % p + b % p) % p;
}
long long fpow(long long n, long long k, long long p = 1000000007) {
  long long r = 1;
  for (; k; k >>= 1) {
    if (k & 1) r = r * n % p;
    n = n * n % p;
  }
  return r;
}
long long inv(long long a, long long p = 1000000007) {
  return fpow(a, p - 2, p);
}
long long inv_euclid(long long a, long long m = 1000000007) {
  long long m0 = m;
  long long y = 0, x = 1;
  if (m == 1) return 0;
  while (a > 1) {
    long long q = a / m;
    long long t = m;
    m = a % m, a = t;
    t = y;
    y = x - q * y;
    x = t;
  }
  if (x < 0) x += m0;
  return x;
}
long long bin[103][103];
void mult_mat(long long m, long long ans[][100], long long bin[][100]) {
  long long mult[m][m];
  for (long long i = 0; i < m; i++) {
    for (long long j = 0; j < m; j++) {
      mult[i][j] = 0;
      for (long long k = 0; k < m; k++) {
        mult[i][j] += ans[i][k] * bin[k][j];
        if (mult[i][j] >= 1000000007) {
          mult[i][j] %= 1000000007;
        }
      }
    }
  }
  for (long long i = 0; i < m; i++) {
    for (long long j = 0; j < m; j++) {
      ans[i][j] = mult[i][j];
    }
  }
}
void pow_mat(long long n, long long fin[][100], long long m) {
  long long ans[m][100];
  long long b[m][100];
  for (long long i = 0; i < m; i++) {
    for (long long j = 0; j < m; j++) {
      ans[i][j] = bin[i][j];
      b[i][j] = bin[i][j];
    }
  }
  n--;
  while (n > 0) {
    if (n % 2 == 1) {
      mult_mat(m, ans, b);
      n--;
    } else {
      n = n / 2;
      mult_mat(m, b, b);
    }
  }
  for (long long i = 0; i < m; i++) {
    for (long long j = 0; j < m; j++) {
      fin[i][j] = ans[i][j];
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  long long n, m;
  cin >> n >> m;
  bin[0][0] = 1;
  bin[0][m - 1] = 1;
  for (long long i = 1; i < m; i++) {
    bin[i][i - 1] = 1;
  }
  if (n < m) {
    cout << 1 << "\n";
  } else {
    long long fin[m + 1][100];
    pow_mat(n - m + 1, fin, m);
    long long ans = 0;
    for (long long i = 0; i < m; i++) {
      ans += fin[0][i];
      if (ans >= 1000000007) {
        ans -= 1000000007;
      }
    }
    cout << ans << "\n";
  }
}
