#include <bits/stdc++.h>
const int default_mod = 1000000007;
template <typename T>
class Matrix {
  int sz;
  int mod;

 public:
  std::vector<std::vector<T>> A;
  int size() { return sz; }
  Matrix() {}
  Matrix(std::vector<std::vector<T>> v, int m = default_mod) {
    mod = m;
    sz = v.size();
    assert(sz > 0);
    assert(sz == (int)(v[0].size()));
    A.clear();
    A.resize(sz, std::vector<T>(sz, 0));
    for (int i = 0; i < sz; ++i) {
      for (int j = 0; j < sz; ++j) {
        A[i][j] = v[i][j];
      }
    }
  }
  Matrix(Matrix<T> &B, int m = default_mod) {
    mod = m;
    sz = B.sz;
    A.clear();
    A.resize(sz, std::vector<T>(sz));
    for (int i = 0; i < sz; ++i) {
      for (int j = 0; j < sz; ++j) {
        A[i][j] = B[i][j];
      }
    }
  }
  Matrix(int n, int m = default_mod) {
    mod = m;
    sz = n;
    A.clear();
    A.resize(sz, std::vector<T>(sz, 0));
  }
  void to_I() {
    A.clear();
    A.resize(sz, std::vector<T>(sz, 0));
    for (int i = 0; i < sz; ++i) {
      A[i][i] = 1;
    }
  }
  void print() {
    for (int i = 0; i < sz; ++i) {
      for (int j = 0; j < sz; ++j) {
        std::cout << A[i][j] << " ";
      }
      std::cout << std::endl;
    }
  }
  std::vector<T> &operator[](int i) { return A[i]; }
  Matrix<T> &operator+=(Matrix<T> B) {
    for (int i = 0; i < sz; ++i) {
      for (int j = 0; j < sz; ++j) {
        A[i][j] += B[i][j];
        A[i][j] %= mod;
      }
    }
    return (*this);
  }
  Matrix<T> &operator*=(Matrix<T> B) {
    std::vector<std::vector<T>> C(sz, std::vector<T>(sz, 0));
    for (int i = 0; i < sz; ++i) {
      for (int j = 0; j < sz; ++j) {
        for (int k = 0; k < sz; ++k) {
          C[i][j] += (A[i][k] * B[k][j]) % mod;
          C[i][j] %= mod;
        }
      }
    }
    A = C;
    return (*this);
  }
  Matrix<T> operator*(Matrix<T> B) {
    Matrix<T> C(sz, mod);
    for (int i = 0; i < sz; ++i) {
      for (int j = 0; j < sz; ++j) {
        for (int k = 0; k < sz; ++k) {
          C[i][j] += (A[i][k] * B[k][j]) % mod;
          C[i][j] %= mod;
        }
      }
    }
    return C;
  }
  std::vector<T> operator*(std::vector<T> v) {
    assert(sz = (int)(v.size()));
    std::vector<T> res(sz, 0);
    for (int i = 0; i < sz; ++i) {
      for (int j = 0; j < sz; ++j) {
        res[i] += (A[i][j] * v[j]) % mod;
        res[i] %= mod;
      }
    }
    return res;
  }
  Matrix<T> &operator^=(long long k) {
    Matrix<T> B(sz, mod);
    B.to_I();
    while (k > 0) {
      if (k & 1) B *= *this;
      *this *= *this;
      k = k >> (1ll);
    }
    A = B.A;
    return (*this);
  }
};
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll << 50;
template <typename T>
void printv(const vector<T> &s) {
  for (int i = 0; i < (int)(s.size()); ++i) {
    cout << s[i];
    if (i == (int)(s.size()) - 1)
      cout << endl;
    else
      cout << " ";
  }
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  ll n, m;
  cin >> n >> m;
  vvll tmp(m, vll(m));
  tmp[0][0] = 1;
  tmp[0][m - 1] = 1;
  for (int i = 1; i < m; ++i) {
    tmp[i][i - 1] = 1;
  }
  Matrix<ll> A(tmp);
  A ^= n;
  vll tmp2(m);
  tmp2[0] = 1;
  cout << (A * tmp2)[0] << endl;
}
