#include <bits/stdc++.h>
using namespace std;
const long long M = 1000 * 1000 * 1000 + 7;
vector<vector<long long>> mult(const vector<vector<long long>> &x,
                               const vector<vector<long long>> &y, int n) {
  vector<vector<long long>> res;
  res.resize(n);
  for (int i = 0; i < (n); i++) res[i].resize(n, 0);
  for (int i = 0; i < (n); i++) {
    for (int j = 0; j < (n); j++) {
      long long sum = 0;
      for (int k = 0; k < (n); k++) {
        sum += x[i][k] * y[k][j];
        sum %= M;
      }
      res[i][j] = sum;
    }
  }
  return res;
}
vector<vector<long long>> unit;
vector<vector<long long>> pow(vector<vector<long long>> x, long long n,
                              int size) {
  if (n == 0) {
    return unit;
  }
  if (n % 2 == 0) {
    auto m = pow(x, n / 2, size);
    return mult(m, m, size);
  } else {
    auto m = pow(x, n - 1, size);
    return mult(m, x, size);
  }
}
void print(vector<vector<long long>> m, int size) {
  for (int i = 0; i < (size); i++) {
    for (int j = 0; j < (size); j++) {
      cout << m[i][j] << " ";
    }
    cout << endl;
  }
}
void init_unit(int n) {
  unit.resize(n);
  for (int i = 0; i < (n); i++) {
    unit[i].resize(n);
  }
  for (int i = 0; i < (n); i++) {
    for (int j = 0; j < (n); j++) {
      if (i == j)
        unit[i][i] = 1;
      else
        unit[i][j] = 0;
    }
  }
}
int main() {
  do {
    ios::sync_with_stdio(0);
    cin.tie(0);
  } while (0);
  long long n;
  int m;
  cin >> n >> m;
  init_unit(m);
  vector<vector<long long>> x;
  x.resize(m);
  for (int i = 0; i < (m); i++) x[i].resize(m, 0);
  x[0][0] = 1;
  x[0][m - 1] = 1;
  for (int i = 1; i < m; i++) {
    x[i][i - 1] = 1;
  }
  auto res = pow(x, n, m);
  cout << res[0][0] << "\n";
}
