#include <bits/stdc++.h>
using namespace std;
struct Matrix {
  const static int N = 100;
  int n;
  long long v[N][N];
  Matrix(int _n) : n(_n) {
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++) v[i][j] = 0;
  }
  Matrix operator*(const Matrix &o) const {
    Matrix res(n);
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++)
        for (int k = 0; k < n; k++)
          res.v[i][j] = (res.v[i][j] + v[i][k] * o.v[k][j]) % 1000000007;
    return res;
  }
  static Matrix getIdentity(int n) {
    Matrix res(n);
    for (int i = 0; i < n; i++) res.v[i][i] = 1;
    return res;
  }
  Matrix operator^(long long k) const {
    Matrix res = Matrix::getIdentity(n);
    Matrix a = *this;
    while (k) {
      if (k & 1) res = res * a;
      a = a * a;
      k /= 2;
    }
    return res;
  }
};
int main(void) {
  long long N;
  int M;
  scanf("%I64d %d", &N, &M);
  Matrix rec(M);
  rec.v[0][0] = 1;
  rec.v[0][M - 1] = 1;
  for (int i = 1; i < M; i++) {
    rec.v[i][i - 1] = 1;
  }
  rec = rec ^ N;
  printf("%I64d\n", rec.v[0][0]);
}
