#include <bits/stdc++.h>
using namespace std;
long long fastPower(long long base, long long exp, long long mod) {
  base %= mod;
  long long result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % mod;
    base = (base * base) % mod;
    exp >>= 1;
  }
  return result;
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
long long nCr(long long n, long long r, long long mod) {
  if (n < r) return 0;
  if (r == 0) return 1;
  return ((n % mod) * ((nCr(n - 1, r - 1, mod) / r) % mod)) % mod;
}
long long removeAt(long long code, int idx, int val, long long BASE,
                   long long mod) {
  return (code - (val * fastPower(BASE, idx, mod)) % mod + mod) % mod;
}
long long addAt(long long code, int idx, int val, long long BASE,
                long long mod) {
  return (code + (val * fastPower(BASE, idx, mod)) % mod) % mod;
}
long long shiftLeft(long long code, long long BASE, long long mod) {
  return (code * BASE) % mod;
}
long long shiftRight(long long code, long long BASE, long long mod) {
  return (code * fastPower(BASE, mod - 2, mod) % mod) % mod;
}
const int N = 1e6 + 5;
bool ok[27][27];
vector<vector<long long> > init(int r, int c, int val) {
  return vector<vector<long long> >(r, vector<long long>(c, val));
}
vector<vector<long long> > I(int n) {
  vector<vector<long long> > ret = init(n, n, 0);
  for (int i = 0; i < n; ++i) ret[i][i] = 1;
  return ret;
}
vector<vector<long long> > mult(const vector<vector<long long> >& a,
                                const vector<vector<long long> >& b) {
  vector<vector<long long> > ret = init(a.size(), b[0].size(), 0);
  for (int i = 0; i < a.size(); ++i) {
    for (int k = 0; k < a[0].size(); ++k) {
      if (!a[i][k]) continue;
      for (int j = 0; j < b[0].size(); ++j) {
        ret[i][j] += (a[i][k] * b[k][j]) % 1000000007;
        ret[i][j] %= 1000000007;
      }
    }
  }
  return ret;
}
vector<vector<long long> > mat_pow(const vector<vector<long long> >& a,
                                   long long p) {
  if (!p) return I(a.size());
  if (p == 1ll) return a;
  vector<vector<long long> > x = mult(a, a);
  vector<vector<long long> > xx = mat_pow(x, p / 2ll);
  if (p & 1ll) return mult(a, xx);
  return xx;
}
int main() {
  long long n;
  int m;
  scanf("%lld", &n);
  scanf("%d", &m);
  if (n < m) return puts("1");
  vector<vector<long long> > initial = init(1, m, 1);
  vector<vector<long long> > trans = init(m, m, 0);
  trans[0][0] = 1;
  trans[m - 1][0] = 1;
  for (int i = 1; i < m; ++i) {
    trans[i - 1][i] = 1;
  }
  trans = mat_pow(trans, n - m + 1);
  vector<vector<long long> > res = mult(initial, trans);
  printf("%d\n", res[0][0]);
  return 0;
}
