#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
void add(long long &a, long long b) {
  a += b;
  if (a >= mod) a -= mod;
}
long long sum(long long a, long long b) {
  a += b;
  if (a >= mod) a -= mod;
  return a;
}
long long sub(long long a, long long b) {
  a -= b;
  if (a < 0) a += mod;
  return a;
}
long long mul(long long a, long long b) { return ((long long)a * b) % mod; }
long long power(long long a, long long b) {
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = mul(res, a);
    a = mul(a, a);
    b >>= 1;
  }
  return res;
}
struct matrix {
  long long n, m;
  vector<vector<long long>> a;
  matrix(const vector<vector<long long>> &b) {
    a = b;
    n = b.size();
    m = b[0].size();
  }
  matrix(long long _n) {
    a.resize(_n, vector<long long>(_n));
    n = _n;
    m = _n;
    for (long long i = 0; i < n; ++i) {
      a[i][i] = 1;
    }
  }
  matrix mul(const matrix &b) const {
    long long k = b.a[0].size();
    vector<vector<long long>> res(n, vector<long long>(k));
    for (long long i = 0; i < n; ++i) {
      for (long long j = 0; j < k; ++j) {
        for (long long t = 0; t < m; ++t) {
          add(res[i][j], ::mul(a[i][t], b.a[t][j]));
        }
      }
    }
    return res;
  }
};
matrix powerMatrix(matrix a, long long b) {
  matrix res((long long)a.a.size());
  while (b > 0) {
    if (b & 1) res = res.mul(a);
    a = a.mul(a);
    b >>= 1;
  }
  return res;
}
void exGcd(long long a, long long b, long long &x, long long &y) {
  if (b == 0) {
    x = 1;
    y = 0;
  } else {
    long long x1, y1;
    exGcd(b, a % b, x1, y1);
    x = y1;
    y = x1 - (a / b) * y1;
  }
}
long long inv(long long a) { return power(a, mod - 2); }
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.setf(ios::fixed);
  cout.precision(20);
  long long n, m;
  cin >> n >> m;
  if (n < m) {
    cout << "1\n";
    exit(0);
  }
  vector<vector<long long>> a(1, vector<long long>(m));
  a[0][0] = 1;
  for (long long i = 1; i < m; ++i) {
    a[0][i] = a[0][i - 1];
  }
  vector<vector<long long>> b(m, vector<long long>(m));
  for (long long j = 0; j + 1 < m; ++j) {
    b[j + 1][j] = 1;
  }
  b[0][m - 1] = 1;
  b[m - 1][m - 1] = 1;
  matrix c(a);
  matrix d(b);
  d = powerMatrix(d, n - m + 1);
  c = c.mul(d);
  cout << c.a[0][m - 1] << '\n';
}
