#include <bits/stdc++.h>
using namespace std;
int mod = (int)1e9 + 7;
long long n, m;
int add(int a, int b) { return (a + b) % mod; }
int mul(int a, int b) { return (a * 1LL * b) % mod; }
struct MATRIX {
  vector<vector<int> > vec;
  MATRIX() {}
  MATRIX(int n) {
    for (int i = 0; i < n; i++) {
      vec.push_back(vector<int>(n, 0));
    }
  }
  MATRIX operator*(const MATRIX &A) {
    MATRIX res(A.vec.size());
    for (int i = 0; i < A.vec.size(); i++) {
      for (int j = 0; j < A.vec[i].size(); j++) {
        for (int k = 0; k < A.vec[i].size(); k++) {
          res.vec[i][j] = add(res.vec[i][j], mul(vec[i][k], A.vec[k][j]));
        }
      }
    }
    return res;
  }
};
MATRIX tr;
MATRIX binpow(MATRIX A, long long n) {
  MATRIX res(A.vec.size());
  for (int i = 0; i < A.vec.size(); i++) {
    res.vec[i][i] = 1;
  }
  while (n) {
    if (n & 1) {
      res = res * A;
    }
    A = A * A;
    n >>= 1;
  }
  return res;
}
int main() {
  cin >> n >> m;
  tr = MATRIX(m);
  if (n < m) {
    cout << 1;
    return 0;
  }
  for (int i = 0; i < tr.vec.size(); i++) {
    for (int j = 0; j < tr.vec[i].size(); j++) {
      if (j == i - 1) {
        tr.vec[i][j] = 1;
      }
    }
  }
  tr.vec[0][m - 1] = 1;
  tr.vec[m - 1][m - 1] = 1;
  MATRIX res = binpow(tr, n);
  printf("%d", res.vec[m - 1][m - 1]);
}
