#include <bits/stdc++.h>
using namespace std;
long long n, m;
vector<vector<long long>> a;
vector<vector<long long>> mul(vector<vector<long long>>& a,
                              vector<vector<long long>>& b) {
  vector<vector<long long>> ret(a.size(), vector<long long>(b.size(), 0));
  for (int i = 0; i < a.size(); ++i) {
    for (int j = 0; j < b[0].size(); ++j) {
      for (int k = 0; k < b.size(); ++k) {
        ret[i][j] += a[i][k] * b[k][j] % 1000000007;
        if (ret[i][j] >= 1000000007) {
          ret[i][j] -= 1000000007;
        }
      }
    }
  }
  return ret;
}
vector<vector<long long>> power(long long b) {
  if (b == 1) {
    return a;
  }
  vector<vector<long long>> x = power(b / 2);
  x = mul(x, x);
  if (b % 2 == 1) {
    x = mul(x, a);
  }
  return x;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  if (n < m) {
    cout << 1 << "\n";
    return 0;
  }
  a.resize(m, vector<long long>(m, 0));
  vector<vector<long long>> f(m, vector<long long>(1, 1));
  a[0][0] = 1;
  a[0][m - 1] = 1;
  int i = 1, j = 0;
  while (i < m) {
    a[i][j] = 1;
    ++i;
    ++j;
  }
  vector<vector<long long>> help = power(n - m + 1);
  cout << mul(help, f)[0][0] << "\n";
  return 0;
}
