#include <bits/stdc++.h>
using namespace std;
unsigned long long mod = 1000000007;
vector<vector<unsigned long long> > mult_mat(
    vector<vector<unsigned long long> > a,
    vector<vector<unsigned long long> > b) {
  int n = a.size();
  vector<vector<unsigned long long> > res(n, vector<unsigned long long>(n, 0));
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      for (int k = 0; k < n; ++k) {
        res[i][j] += a[i][k] * b[k][j];
        if (res[i][j] >= mod) res[i][j] %= mod;
      }
    }
  }
  return res;
}
vector<vector<unsigned long long> > pow_mat(
    vector<vector<unsigned long long> > a, unsigned long long n) {
  vector<vector<unsigned long long> > res = a;
  n--;
  while (n) {
    if (n % 2 == 1) {
      res = mult_mat(res, a);
      n--;
    }
    a = mult_mat(a, a);
    n >>= 1;
  }
  return res;
}
int main() {
  unsigned long long n, m;
  cin >> n >> m;
  if (n < m) {
    cout << "1";
  } else {
    vector<vector<unsigned long long> > a(m, vector<unsigned long long>(m, 0));
    a[0][0] = 1;
    a[0][m - 1] = 1;
    for (int i = 1; i < m; ++i) a[i][i - 1] = 1;
    a = pow_mat(a, n - m + 1);
    unsigned long long res = 0;
    for (int i = 0; i < m; ++i) {
      res = (res + a[0][i]);
      if (res >= mod) res %= mod;
    }
    cout << res;
  }
  return 0;
}
