#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse4")
using namespace std;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T>
void __print(const T &x) {
  int f = 0;
  cerr << '{';
  for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cerr << ", ";
  _print(v...);
}
template <typename T, typename TT>
ostream &operator<<(ostream &os, const pair<T, TT> &t) {
  return os << t.first << " " << t.second;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &t) {
  for (auto &i : t) os << i << " ";
  return os;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
  for (T &t : v) is >> t;
  return is;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, vector<pair<T1, T2>> &v) {
  for (pair<T1, T2> &t : v) is >> t.first >> t.second;
  return is;
}
const long long mod = 1e9 + 7;
vector<vector<long long>> calc(vector<vector<long long>> &a,
                               vector<vector<long long>> &b) {
  long long m = b.size();
  vector<vector<long long>> ans(m, vector<long long>(m, 0));
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < m; j++) {
      for (int k = 0; k < m; k++) {
        (ans[i][j] += (a[i][k] * b[k][j]) % mod) %= mod;
      }
    }
  }
  return ans;
}
vector<vector<long long>> modpow(vector<vector<long long>> &v, long long p) {
  vector<vector<long long>> ans = v;
  p--;
  while (p) {
    if (p & 1) ans = calc(ans, v);
    v = calc(v, v), p /= 2;
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n, m;
  cin >> n >> m;
  vector<long long> b(m + 1);
  b[0] = 0, b[1] = 1;
  for (int i = 2; i <= m; i++) {
    b[i] = b[i - 1];
    if (i >= m) b[i] += b[i - m];
  }
  vector<vector<long long>> v(m, vector<long long>(m, 0));
  for (int i = 1; i < m; i++) v[i - 1][i] = 1;
  v[m - 1][0] = 1, v[m - 1][m - 1] = 1;
  vector<vector<long long>> pw = modpow(v, n);
  long long ans = 0;
  ;
  for (int i = 0; i < m; i++) {
    (ans += (pw[0][i] * b[i + 1]) % mod) %= mod;
  }
  cout << ans << '\n';
  return 0;
}
