#include <bits/stdc++.h>
using namespace std;
int power(long long x, long long y, long long p) {
  long long res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
int modInverse(long long n) {
  long long p = 1000000007;
  return power(n, p - 2, p);
}
int min(int a, int b, int c) { return min(a, min(b, c)); }
int max(int a, int b, int c) { return max(a, max(b, c)); }
inline void swap(int &a, int &b) {
  int t = a;
  a = b;
  b = t;
}
bool cmp(int a, int b) { return a > b; }
template <typename T>
struct Matrix {
  vector<vector<T> > val;
  Matrix() {}
  Matrix(vector<vector<T> > _val) { val = _val; }
  Matrix operator*(Matrix _val) {
    Matrix<T> ret;
    int r = val.size(), c = _val.val[0].size(), m = val[0].size();
    ret.val.resize(r, vector<T>(c, 0));
    int i, j;
    for (int i = 0; i < r; i++) {
      for (int j = 0; j < c; j++) {
        for (int k = 0; k < m; k++) {
          ret.val[i][j] =
              (ret.val[i][j] + val[i][k] * _val.val[k][j]) % 1000000007;
        }
      }
    }
    return ret;
  }
  Matrix identity(int k) {
    vector<vector<T> > A(k, vector<T>(k, 0));
    for (int i = 0; i < k; i++) A[i][i]++;
    return Matrix<T>(A);
  }
};
template <typename T>
Matrix<T> exp(Matrix<T> A, long long n) {
  int sz = A.val.size();
  if (n == 0) return A.identity(sz);
  Matrix<T> ret = exp(A, n / 2);
  ret = ret * ret;
  if (n % 2) ret = ret * A;
  return ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n;
  int m, i, j;
  cin >> n >> m;
  vector<vector<long long> > A(m, vector<long long>(m, 0)),
      B(m, vector<long long>(1, 1));
  A[0][0] = A[0][m - 1] = 1;
  for (i = 1; i < m; i++) A[i][i - 1] = 1;
  Matrix<long long> m1(A), m2(B);
  m1 = exp(m1, n);
  m1 = m1 * m2;
  cout << m1.val[m - 1][0];
  return 0;
}
