#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
struct matrix {
  vector<vector<long long>> m;
  matrix(int n) : m(n, vector<long long>(n)) {}
  static matrix identity(int n) {
    matrix m(n);
    for (int i = 0; i < n; i++) m.m[i][i] = 1;
    return m;
  }
  matrix operator*(matrix &rhs) {
    matrix res(m.size());
    for (int i = 0; i < (int)m.size(); i++)
      for (int k = 0; k < (int)m.size(); k++)
        for (int j = 0; j < (int)m.size(); j++)
          res.m[i][j] = (res.m[i][j] + m[i][k] * rhs.m[k][j]) % MOD;
    return res;
  }
  vector<long long> operator*(vector<long long> v) {
    vector<long long> res(v.size());
    for (int i = 0; i < (int)m.size(); i++)
      for (int j = 0; j < (int)m.size(); j++)
        res[i] = (res[i] + m[i][j] * v[j]) % MOD;
    return res;
  }
  matrix pow(long long x) {
    matrix res = identity(m.size()), a = *this;
    while (x) {
      if (x & 1) res = res * a;
      a = a * a;
      x >>= 1;
    }
    return res;
  }
};
long long n;
int m;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n >> m;
  matrix tf(m);
  tf.m[0][0] = tf.m[0][m - 1] = 1;
  for (int i = 1; i < m; i++) tf.m[i][i - 1] = 1;
  tf = tf.pow(n);
  auto res = tf * vector<long long>(m, 1);
  cout << res.back() << "\n";
  return 0;
}
