#include <bits/stdc++.h>
using namespace std;
const long long d4i[4] = {-1, 0, 1, 0}, d4j[4] = {0, 1, 0, -1};
const long long d8i[8] = {-1, -1, 0, 1, 1, 1, 0, -1},
                d8j[8] = {0, 1, 1, 1, 0, -1, -1, -1};
long long power(long long x, long long y, long long p) {
  long long res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) {
      res = (res * x) % p;
    }
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
long long modInverse(long long a, long long p) { return power(a, p - 2, p); }
void gcd(long long a, long long b, long long &d, long long &u, long long &v) {
  if (b == 0) {
    d = a;
    u = 1;
    v = 0;
  } else {
    gcd(b, a % b, d, v, u);
    v -= a / b * u;
  }
}
long long Inverse(long long a, long long m) {
  a %= m;
  if (a < 0) a += m;
  long long d, u, v;
  gcd(a, m, d, u, v);
  assert(d == 1);
  u %= m;
  if (u < 0) u += m;
  return u;
}
long long gcd(long long x, long long y) {
  if (x == 0 || y == 0) {
    return max(y, x);
  }
  return gcd(y % x, x);
}
long long gcdExtended(long long a, long long b, long long &x, long long &y) {
  if (a == 0) {
    x = 0;
    y = 1;
    return b;
  }
  long long x1, y1;
  long long gcd = gcdExtended(b % a, a, x1, y1);
  x = y1 - (b / a) * x1;
  y = x1;
  return gcd;
};
const long long siz = 100;
long long m;
struct mat {
  long long a[siz][siz] = {0};
  mat(long long id = 1) {
    memset(a, 0, sizeof(a));
    for (long long i = 0; i < siz; i++) a[i][i] = id;
  }
  mat operator*(const mat &o) const {
    long long n = m;
    mat res(0);
    for (long long i = 0; i < n; i++)
      for (long long k = 0; k < n; k++)
        for (long long j = 0; j < n; j++)
          res.a[i][j] = (res.a[i][j] + a[i][k] * o.a[k][j]) % 1000000007;
    return res;
  }
};
mat binpow(mat a, long long n) {
  mat ans(1);
  while (n) {
    if (n & 1) ans = ans * a;
    a = a * a;
    n >>= 1;
  }
  return ans;
}
void print(mat &a) {
  for (long long i = 0; i < m; i++) {
    for (long long j = 0; j < m; j++) cout << a.a[i][j] << " ";
    cout << '\n';
  }
}
int main() {
  long long n;
  scanf("%lld %lld", &(n), &(m));
  if (n < m) {
    cout << 1 << endl;
    return 0;
  }
  mat a(0);
  a.a[0][0] = 1;
  a.a[0][m - 1] = 1;
  for (long long i = 1; i < m; i++) {
    a.a[i][i - 1] = 1;
  }
  auto ans = binpow(a, n - m + 1);
  long long ret = 0;
  for (long long i = 0; i < m; i++) {
    ret += ans.a[0][i];
    ret %= 1000000007;
  }
  cout << ret << endl;
}
