Reziba has many magic gems. Each magic gem can be split into $$$M$$$ normal gems. The amount of space each magic (and normal) gem takes is $$$1$$$ unit. A normal gem cannot be split.Reziba wants to choose a set of magic gems and split some of them, so the total space occupied by the resulting set of gems is $$$N$$$ units. If a magic gem is chosen and split, it takes $$$M$$$ units of space (since it is split into $$$M$$$ gems); if a magic gem is not split, it takes $$$1$$$ unit.How many different configurations of the resulting set of gems can Reziba have, such that the total amount of space taken is $$$N$$$ units? Print the answer modulo $$$1000000007$$$ ($$$10^9+7$$$). Two configurations are considered different if the number of magic gems Reziba takes to form them differs, or the indices of gems Reziba has to split differ.

The input contains a single line consisting of $$$2$$$ integers $$$N$$$ and $$$M$$$ ($$$1 \le N \le 10^{18}$$$, $$$2 \le M \le 100$$$).

Print one integer, the total number of configurations of the resulting set of gems, given that the total amount of space taken is $$$N$$$ units. Print the answer modulo $$$1000000007$$$ ($$$10^9+7$$$).

NoteIn the first example each magic gem can split into $$$2$$$ normal gems, and we know that the total amount of gems are $$$4$$$.Let $$$1$$$ denote a magic gem, and $$$0$$$ denote a normal gem.The total configurations you can have is:   $$$1 1 1 1$$$ (None of the gems split);  $$$0 0 1 1$$$ (First magic gem splits into $$$2$$$ normal gems);  $$$1 0 0 1$$$ (Second magic gem splits into $$$2$$$ normal gems);  $$$1 1 0 0$$$ (Third magic gem splits into $$$2$$$ normal gems);  $$$0 0 0 0$$$ (First and second magic gems split into total $$$4$$$ normal gems). Hence, answer is $$$5$$$.

// Igorjan94, template version from 13 October 2017. C++17 version, modified 07 August 2018 (&&, whole) {{{
#include <bits/stdc++.h>

using namespace std;

#define FILENAME "input"

#define FOR(i, m, n) for (int i = m; i <  (int) (n); ++i)
#define ROF(i, m, n) for (int i = m; i >= (int) (n); --i)
#define forn(i, n)   for (int i = 0; i < (int) (n); ++i)
#define  fori1(n)    for (int i = 1; i < (int) (n); ++i)
#define  forj1(n)    for (int j = 1; j < (int) (n); ++j)
#define   fori(n)    for (int i = 0; i < (int) (n); ++i)
#define   forj(n)    for (int j = 0; j < (int) (n); ++j)

typedef  pair<int, int>   pii;
typedef  valarray<int>    va;
typedef   vector<int>     vi;
typedef    long long      ll;

#define    pb    push_back
#define whole(a) begin(a), end(a)
#define   next   next__
#define   prev   prev__
#define  count   count__

#define ints(a...)  int a; readln(a)
#define wr(args...) err(#args, args)

#define ttt12i template<class T1, class T2> inline
#define  tthti template<class H, class...T> inline
#define  ttta  template<class... Args> inline
#define  ttti  template<class T> inline

const int MOD = 1000000007;
const int INTMAX = numeric_limits<int>::max();
const ll LLMAX = numeric_limits<ll>::max();

void writeln(){cout<<"\n";}ttti void print(T&& a);ttti void priws(T&& a);ttti void read(T& a);
ttta void readln(Args&... args){(read(args),...);}tthti void writeln(H&& h,T&&...t){priws(h);(print(t),...);writeln();}
ttti void writeln_range(T f,T s){if(f!=s)for(auto i=f;i!=s;++i)writeln(*i);}
vector<string>split(string&s,string d){vector<string>v;size_t p=0;while((p=s.find(d))!=string::npos)v.pb(s.substr(0,p)),s.erase(0,p+d.length());v.pb(s);return v;}
ttta void err(string v,Args...args){auto vv=split(v,", ");auto it=vv.begin();(writeln(*it++,"=",args),...);}

//binpow
template<typename T>
T binpow(T a, ll n)
{
    assert(n > 0);
    T res = a; --n;
    while (n > 0)
    {
        if (n & 1)
            res *= a;
        a *= a;
        n >>= 1;
    }
    return res;
}

//matrix
template<typename T>
struct matrix
{
#define vectorOrValarray template<template<typename> typename C, typename = enable_if_t<is_same<vector<T>, C<T>>::value || is_same<valarray<T>, C<T>>::value>>
    friend void swap(matrix& lhs, matrix& rhs)
    {
        swap(lhs.n, rhs.n);
        swap(lhs.m, rhs.m);
        swap(lhs.a, rhs.a);
    }

    matrix(int n, int m) : n(n), m(m)
    {
        a.resize(n, valarray(T(), m));
        fori(::min(n, m)) a[i][i] = T(1);
    }

    matrix(int n, int m, const T& initial) : n(n), m(m)
    {
        a.resize(n, valarray(initial, m));
    }

    matrix(const vector<vector<T>>& rhs)
    {
        n = size(rhs);
        m = size(n == 0 ? 0 : rhs[0]);
        a.resize(n, valarray(T(), m));
        fori(n) forj(m) a[i][j] = rhs[i][j];
    }

    matrix(const vector<T>& rhs)
    {
        n = size(rhs);
        m = 1;
        a.resize(n, valarray<T>(0, 1));
        fori(n) a[i] = rhs[i];
    }

    matrix(const valarray<T>& rhs)
    {
        n = size(rhs);
        m = 1;
        a.resize(n, valarray<T>(0, 1));
        fori(n) a[i] = rhs[i];
    }

    matrix(const matrix<T>& rhs) : n(rhs.n), m(rhs.m), a(rhs.a) {}

    matrix& operator=(const matrix& rhs)
    {
        if (&rhs == this)
            return *this;
        matrix temp(rhs);
        swap(*this, temp);
        return *this;
    }

    matrix& operator=(const T& rhs)
    {
        matrix temp(n, m, rhs);
        swap(*this, temp);
        return *this;
    }

    vectorOrValarray matrix& operator=(const C<T>& rhs)
    {
        matrix temp(size(rhs), 1, 0);
        fori(temp.n) a[i][0] = rhs[i];
        swap(*this, temp);
        return *this;
    }

    valarray<T>& operator[](int i) { return a[i]; }
    const valarray<T>& operator[](int i) const { return a[i]; }

    matrix& operator+=(const matrix& rhs) { a += rhs.a; return *this; }
    matrix& operator-=(const matrix& rhs) { a -= rhs.a; return *this; }
    matrix& operator+=(const T& rhs) { fori(n) a[i] += rhs; return *this; }
    matrix& operator-=(const T& rhs) { fori(n) a[i] -= rhs; return *this; }
    matrix& operator*=(const T& rhs) { fori(n) a[i] *= rhs; return *this; }
    matrix& operator/=(const T& rhs) { fori(n) a[i] /= rhs; return *this; }
    matrix& operator%=(const T& rhs) { fori(n) a[i] %= rhs; return *this; }
    matrix& operator*=(const matrix& rhs) {
        assert(m == rhs.n);
        matrix temp(n, rhs.m, 0);
        fori(n) forj(m) forn(k, rhs.m) temp.a[i][k] += a[i][j] * rhs[j][k];
        return *this = temp;
    }

    matrix& operator|=(const matrix& rhs) {
        assert(n == rhs.n);
        matrix temp(n, m + rhs.m, 0);
        fori(n) forj(m) temp[i][j] = a[i][j];
        fori(n) forj(rhs.m) temp[i][j + m] = rhs[i][j];
        return *this = temp;
    }

    matrix& operator^=(ll i) {
        assert(i >= 0);
        if (i == 0) return *this = matrix(n, m);
        return *this = binpow(*this, std::abs(i));
    }
    vectorOrValarray C<T> operator*(const C<T>& rhs) {
        assert(m == size(rhs));
        C<T> ans(n);
        fori(n) forn(k, m) ans[i] += a[i][k] * rhs[k];
        return ans;
    }
    vectorOrValarray friend C<T> operator*(const C<T>& lhs, const matrix& rhs) {
        assert(size(lhs) == rhs.n);
        C<T> ans(rhs.m);
        forj(rhs.m) forn(k, rhs.n) ans[j] += lhs[k] * rhs[k][j];
        return ans;
    }
    matrix operator-() { return *this *= -1; }

    friend matrix operator+(matrix lhs, const matrix& rhs) { lhs += rhs; return lhs; }
    friend matrix operator-(matrix lhs, const matrix& rhs) { lhs += rhs; return lhs; }
    friend matrix operator*(matrix lhs, const matrix& rhs) { lhs *= rhs; return lhs; }
    friend matrix operator|(matrix lhs, const matrix& rhs) { lhs |= rhs; return lhs; }
    friend matrix operator+(matrix lhs, const T& rhs) { lhs += rhs; return lhs; }
    friend matrix operator-(matrix lhs, const T& rhs) { lhs -= rhs; return lhs; }
    friend matrix operator*(matrix lhs, const T& rhs) { lhs *= rhs; return lhs; }
    friend matrix operator/(matrix lhs, const T& rhs) { lhs /= rhs; return lhs; }
    friend matrix operator%(matrix lhs, const T& rhs) { lhs %= rhs; return lhs; }
    friend matrix operator^(matrix lhs, const ll& rhs) { lhs ^= rhs; return lhs; }
    vectorOrValarray matrix operator|=(const C<T>& rhs) { return *this |= matrix(rhs); }
    T max() { return a.max(); }
    T min() { return a.min(); }
    T sum() { return a.sum(); }

    matrix transpose() {
        matrix temp(m, n, 0);
        fori(n) forj(m) temp[i][j] = a[j][i];
        return temp;
    }

    T normalize(int index) {
        T g = 1;
        bool found = false;
        for (T& x: a[index])
            if (x != 0)
            {
                if (not found) g = x, found = true;
                else g = gcd(g, x);
            }
        a[index] /= g;
        return g;
    }

    void normalize() {
        fori(n) normalize(i);
    }

    T determinant() {
        matrix temp(*this);
        T numerator = 1;
        T denumerator = 1;
        fori(n)
        {
            int nonZero = i;
            while (nonZero < n && !temp[nonZero][i]) ++nonZero;
            if (nonZero == n) return 0;

            swap(temp[i], temp[nonZero]);
            numerator *= temp[i][i];

            FOR(j, i + 1, n)
                if (temp[j][i])
                {
                    T g = gcd(temp[i][i], temp[j][i]);
                    denumerator *= temp[i][i] / g;
                    temp[j] = temp[j] * (temp[i][i] / g) - temp[i] * (temp[j][i] / g);
                }
        }
        writeln(temp); writeln();
        return numerator / denumerator;
    }

    optional<pair<T, matrix<T>>> invert() {
        assert(n == m);
        matrix temp(*this);
        temp |= matrix(n, n);

        auto det = solve(temp);
        if (!det.has_value()) return {};

        matrix ret(n, n, 0);
        auto s = slice(n, n, 1);
        fori(n) ret[i] = temp[i][s];
        return pair(det.value(), ret);
    }

    vectorOrValarray optional<pair<T, C<T>>> solution(const C<T>& b) {
        assert(n == m);
        matrix temp(*this);
        temp |= b;

        auto det = solve(temp);
        if (!det.has_value()) return {};

        C<T> ret(0, n);
        fori(n) ret[i] = temp[i][n];
        return pair(det.value(), ret);
    }

    friend ostream& operator<<(ostream& os, matrix rhs) {
        fori(rhs.n)
        {
            os << rhs.a[i];
            if (i != rhs.n - 1) os << "\n";
        }
        return os;
    }
    friend istream& operator>>(istream& is, matrix& rhs) {
        fori(rhs.n) is >> rhs.a[i];
        return is;
    }

private:
    valarray<valarray<T>> a;
    int n, m;

    static optional<T> solve(matrix& temp) {
        vector<int> permutation(temp.n);
        iota(whole(permutation), 0);

        auto get = [&](int i, int j) {
            return temp[permutation[i]][j];
        };
        auto findNonZero = [&](int i) {
            int nonZero = i;
            while (nonZero < temp.n && !get(nonZero, i)) ++nonZero;
            return nonZero;
        };
        fori(temp.n)
        {
            int nonZero = findNonZero(i);
            if (nonZero == temp.n) return {};
            swap(permutation[i], permutation[nonZero]);
            FOR(j, i + 1, temp.n)
                if (get(j, i))
                    temp[permutation[j]] = temp[permutation[j]] * get(i, i) - temp[permutation[i]] * get(j, i),
                    temp.normalize(permutation[j]);
        }
        ROF(i, temp.n - 1, 0)
            ROF(j, i - 1, 0)
                if (get(j, i))
                    temp[permutation[j]] = temp[permutation[j]] * get(i, i) - temp[permutation[i]] * get(j, i),
                    temp.normalize(permutation[j]);
        fori(temp.n) temp.normalize(i);
        T mx = 0;
        fori(temp.n) mx = std::max(mx, abs(get(i, i)));
        fori(temp.n) temp[permutation[i]] *= mx / get(i, i);
        matrix ret(temp.n, temp.m, 0);
        fori(temp.n) ret[i] = temp[permutation[i]];
        temp = ret;
        return mx;
    }
};
//Igorjan

template<typename T = ll, T mod = MOD>
struct modular
{
    T value = 0;

    modular(){}
    modular(const modular& other) : value(other.value) {}
    modular operator=(const modular& other) { value = other.value; return *this; }
    template<typename T1> modular operator=(const T1& other) { if (other > mod) value = other % mod; else value = other; return *this; }
    template<typename T1> modular(T1 const& t) { if (t > mod) value = t % mod; else value = t; }
    inline modular& operator+=(modular const& t)       { value += t.value; if (value > mod) value -= mod; return *this; }
    inline modular& operator-=(modular const& t)       { value -= t.value; if (value < 0  ) value += mod; return *this; }
    inline modular& operator*=(modular const& t)       { value = (value * t.value) % mod; return *this; }
    inline modular  operator+ (modular const& t) const { return modular(*this) += t; }
    inline modular  operator- (modular const& t) const { return modular(*this) -= t; }
    inline modular  operator* (modular const& t) const { return modular(*this) *= t; }

    inline friend ostream& operator<<(ostream& os, modular const& m) { return os << m.value; }
    inline friend istream& operator>>(istream& is, modular& m) { return is >> m.value; }
};
//}}}

typedef modular<ll, MOD> num;
void run()
{
    ll n, m;
    readln(n, m);
    matrix<num> p(m, m, 0);
    vector<num> v(m--, 1);
    fori(m) p[i + 1][i] = 1;
    p[m][m] = p[0][m] = 1;
    writeln((v * (p ^ max(0ll, n - m))).back());
}

//{{{
int main()
{
#ifndef ONLINE_JUDGE
    double time = clock();
#endif
    ios_base::sync_with_stdio(false);
//    freopen(FILENAME".in", "r", stdin);
//    freopen(FILENAME".out", "w", stdout);
    run();
#ifndef ONLINE_JUDGE
    writeln("execution time =", (clock() - time) / CLOCKS_PER_SEC);
#endif
    return 0;
}

#define a _a
#define n _n
ttti   ostream&operator<<(ostream&os,vector<T>const&a);
ttt12i istream&operator>>(istream&is,pair<T1,T2>&a){return is>>a.first>>a.second;}
ttt12i ostream&operator<<(ostream&os,pair<T1,T2>const&a){return os<<a.first<<" "<<a.second;}
ttti   ostream&operator<<(ostream&os,vector<T>const&a){if(a.size())os<<a[0];else os<<"\n";fori1(a.size())os<<"\n "[is_fundamental<T>::value]<<a[i];return os;}
ttti   ostream&operator<<(ostream&os,valarray<T>const&a){if(a.size())os<<a[0];else os<<"\n";fori1(a.size())os<<"\n "[is_fundamental<T>::value]<<a[i];return os;}
ttti   istream&operator>>(istream&is,vector<T>&a){fori(a.size())is>>a[i];return is;}
ttti   istream&operator>>(istream&is,valarray<T>&a){fori(a.size())is>>a[i];return is;}
ttti void print(T&&a){cout<<" "<<a;}
ttti void priws(T&&a){cout<<a;}
ttti void read(T&a){cin>>a;} //}}}

// Igorjan94, template version from 13 October 2017. C++17 version, modified 07 August 2018 (&&, whole) {{{
#include <bits/stdc++.h>

using namespace std;

#define FILENAME "input"

#define FOR(i, m, n) for (int i = m; i <  (int) (n); ++i)
#define ROF(i, m, n) for (int i = m; i >= (int) (n); --i)
#define forn(i, n)   for (int i = 0; i < (int) (n); ++i)
#define  fori1(n)    for (int i = 1; i < (int) (n); ++i)
#define  forj1(n)    for (int j = 1; j < (int) (n); ++j)
#define   fori(n)    for (int i = 0; i < (int) (n); ++i)
#define   forj(n)    for (int j = 0; j < (int) (n); ++j)

typedef  pair<int, int>   pii;
typedef  valarray<int>    va;
typedef   vector<int>     vi;
typedef    long long      ll;

#define    pb    push_back
#define whole(a) begin(a), end(a)
#define   next   next__
#define   prev   prev__
#define  count   count__

#define ints(a...)  int a; readln(a)
#define wr(args...) err(#args, args)

#define ttt12i template<class T1, class T2> inline
#define  tthti template<class H, class...T> inline
#define  ttta  template<class... Args> inline
#define  ttti  template<class T> inline

const int MOD = 1000000007;
const int INTMAX = numeric_limits<int>::max();
const ll LLMAX = numeric_limits<ll>::max();

void writeln(){cout<<"\n";}ttti void print(T&& a);ttti void priws(T&& a);ttti void read(T& a);
ttta void readln(Args&... args){(read(args),...);}tthti void writeln(H&& h,T&&...t){priws(h);(print(t),...);writeln();}
ttti void writeln_range(T f,T s){if(f!=s)for(auto i=f;i!=s;++i)writeln(*i);}
vector<string>split(string&s,string d){vector<string>v;size_t p=0;while((p=s.find(d))!=string::npos)v.pb(s.substr(0,p)),s.erase(0,p+d.length());v.pb(s);return v;}
ttta void err(string v,Args...args){auto vv=split(v,", ");auto it=vv.begin();(writeln(*it++,"=",args),...);}

//binpow
template<typename T>
T binpow(T a, ll n)
{
    assert(n > 0);
    T res = a; --n;
    while (n > 0)
    {
        if (n & 1)
            res *= a;
        a *= a;
        n >>= 1;
    }
    return res;
}

//matrix
template<typename T>
struct matrix
{
#define vectorOrValarray template<template<typename> typename C, typename = enable_if_t<is_same<vector<T>, C<T>>::value || is_same<valarray<T>, C<T>>::value>>
    friend void swap(matrix& lhs, matrix& rhs)
    {
        swap(lhs.n, rhs.n);
        swap(lhs.m, rhs.m);
        swap(lhs.a, rhs.a);
    }

    matrix(int n, int m) : n(n), m(m)
    {
        a.resize(n, valarray(T(), m));
        fori(::min(n, m)) a[i][i] = T(1);
    }

    matrix(int n, int m, const T& initial) : n(n), m(m)
    {
        a.resize(n, valarray(initial, m));
    }

    matrix(const vector<vector<T>>& rhs)
    {
        n = size(rhs);
        m = size(n == 0 ? 0 : rhs[0]);
        a.resize(n, valarray(T(), m));
        fori(n) forj(m) a[i][j] = rhs[i][j];
    }

    matrix(const vector<T>& rhs)
    {
        n = size(rhs);
        m = 1;
        a.resize(n, valarray<T>(0, 1));
        fori(n) a[i] = rhs[i];
    }

    matrix(const valarray<T>& rhs)
    {
        n = size(rhs);
        m = 1;
        a.resize(n, valarray<T>(0, 1));
        fori(n) a[i] = rhs[i];
    }

    matrix(const matrix<T>& rhs) : n(rhs.n), m(rhs.m), a(rhs.a) {}

    matrix& operator=(const matrix& rhs)
    {
        if (&rhs == this)
            return *this;
        matrix temp(rhs);
        swap(*this, temp);
        return *this;
    }

    matrix& operator=(const T& rhs)
    {
        matrix temp(n, m, rhs);
        swap(*this, temp);
        return *this;
    }

    vectorOrValarray matrix& operator=(const C<T>& rhs)
    {
        matrix temp(size(rhs), 1, 0);
        fori(temp.n) a[i][0] = rhs[i];
        swap(*this, temp);
        return *this;
    }

    valarray<T>& operator[](int i) { return a[i]; }
    const valarray<T>& operator[](int i) const { return a[i]; }

    matrix& operator+=(const matrix& rhs) { a += rhs.a; return *this; }
    matrix& operator-=(const matrix& rhs) { a -= rhs.a; return *this; }
    matrix& operator+=(const T& rhs) { fori(n) a[i] += rhs; return *this; }
    matrix& operator-=(const T& rhs) { fori(n) a[i] -= rhs; return *this; }
    matrix& operator*=(const T& rhs) { fori(n) a[i] *= rhs; return *this; }
    matrix& operator/=(const T& rhs) { fori(n) a[i] /= rhs; return *this; }
    matrix& operator%=(const T& rhs) { fori(n) a[i] %= rhs; return *this; }
    matrix& operator*=(const matrix& rhs) {
        assert(m == rhs.n);
        matrix temp(n, rhs.m, 0);
        fori(temp.n) forj(temp.m) forn(k, m) temp.a[i][j] += a[i][k] * rhs[k][j];
        return *this = temp;
    }

    matrix& operator|=(const matrix& rhs) {
        assert(n == rhs.n);
        matrix temp(n, m + rhs.m, 0);
        fori(n) forj(m) temp[i][j] = a[i][j];
        fori(n) forj(rhs.m) temp[i][j + m] = rhs[i][j];
        return *this = temp;
    }

    matrix& operator^=(ll i) {
        assert(i >= 0);
        if (i == 0) return *this = matrix(n, m);
        return *this = binpow(*this, std::abs(i));
    }
    vectorOrValarray C<T> operator*(const C<T>& rhs) {
        assert(m == size(rhs));
        C<T> ans(n);
        fori(n) forn(k, m) ans[i] += a[i][k] * rhs[k];
        return ans;
    }
    vectorOrValarray friend C<T> operator*(const C<T>& lhs, const matrix& rhs) {
        assert(size(lhs) == rhs.n);
        C<T> ans(rhs.m);
        forj(rhs.m) forn(k, rhs.n) ans[j] += lhs[k] * rhs[k][j];
        return ans;
    }
    matrix operator-() { return *this *= -1; }

    friend matrix operator+(matrix lhs, const matrix& rhs) { lhs += rhs; return lhs; }
    friend matrix operator-(matrix lhs, const matrix& rhs) { lhs += rhs; return lhs; }
    friend matrix operator*(matrix lhs, const matrix& rhs) { lhs *= rhs; return lhs; }
    friend matrix operator|(matrix lhs, const matrix& rhs) { lhs |= rhs; return lhs; }
    friend matrix operator+(matrix lhs, const T& rhs) { lhs += rhs; return lhs; }
    friend matrix operator-(matrix lhs, const T& rhs) { lhs -= rhs; return lhs; }
    friend matrix operator*(matrix lhs, const T& rhs) { lhs *= rhs; return lhs; }
    friend matrix operator/(matrix lhs, const T& rhs) { lhs /= rhs; return lhs; }
    friend matrix operator%(matrix lhs, const T& rhs) { lhs %= rhs; return lhs; }
    friend matrix operator^(matrix lhs, const ll& rhs) { lhs ^= rhs; return lhs; }
    vectorOrValarray matrix operator|=(const C<T>& rhs) { return *this |= matrix(rhs); }
    T max() { return a.max(); }
    T min() { return a.min(); }
    T sum() { return a.sum(); }

    matrix transpose() {
        matrix temp(m, n, 0);
        fori(n) forj(m) temp[i][j] = a[j][i];
        return temp;
    }

    T normalize(int index) {
        T g = 1;
        bool found = false;
        for (T& x: a[index])
            if (x != 0)
            {
                if (not found) g = x, found = true;
                else g = gcd(g, x);
            }
        a[index] /= g;
        return g;
    }

    void normalize() {
        fori(n) normalize(i);
    }

    T determinant() {
        matrix temp(*this);
        T numerator = 1;
        T denumerator = 1;
        fori(n)
        {
            int nonZero = i;
            while (nonZero < n && !temp[nonZero][i]) ++nonZero;
            if (nonZero == n) return 0;

            swap(temp[i], temp[nonZero]);
            numerator *= temp[i][i];

            FOR(j, i + 1, n)
                if (temp[j][i])
                {
                    T g = gcd(temp[i][i], temp[j][i]);
                    denumerator *= temp[i][i] / g;
                    temp[j] = temp[j] * (temp[i][i] / g) - temp[i] * (temp[j][i] / g);
                }
        }
        writeln(temp); writeln();
        return numerator / denumerator;
    }

    optional<pair<T, matrix<T>>> invert() {
        assert(n == m);
        matrix temp(*this);
        temp |= matrix(n, n);

        auto det = solve(temp);
        if (!det.has_value()) return {};

        matrix ret(n, n, 0);
        auto s = slice(n, n, 1);
        fori(n) ret[i] = temp[i][s];
        return pair(det.value(), ret);
    }

    vectorOrValarray optional<pair<T, C<T>>> solution(const C<T>& b) {
        assert(n == m);
        matrix temp(*this);
        temp |= b;

        auto det = solve(temp);
        if (!det.has_value()) return {};

        C<T> ret(0, n);
        fori(n) ret[i] = temp[i][n];
        return pair(det.value(), ret);
    }

    friend ostream& operator<<(ostream& os, matrix rhs) {
        fori(rhs.n)
        {
            os << rhs.a[i];
            if (i != rhs.n - 1) os << "\n";
        }
        return os;
    }
    friend istream& operator>>(istream& is, matrix& rhs) {
        fori(rhs.n) is >> rhs.a[i];
        return is;
    }

private:
    valarray<valarray<T>> a;
    int n, m;

    static optional<T> solve(matrix& temp) {
        vector<int> permutation(temp.n);
        iota(whole(permutation), 0);

        auto get = [&](int i, int j) {
            return temp[permutation[i]][j];
        };
        auto findNonZero = [&](int i) {
            int nonZero = i;
            while (nonZero < temp.n && !get(nonZero, i)) ++nonZero;
            return nonZero;
        };
        fori(temp.n)
        {
            int nonZero = findNonZero(i);
            if (nonZero == temp.n) return {};
            swap(permutation[i], permutation[nonZero]);
            FOR(j, i + 1, temp.n)
                if (get(j, i))
                    temp[permutation[j]] = temp[permutation[j]] * get(i, i) - temp[permutation[i]] * get(j, i),
                    temp.normalize(permutation[j]);
        }
        ROF(i, temp.n - 1, 0)
            ROF(j, i - 1, 0)
                if (get(j, i))
                    temp[permutation[j]] = temp[permutation[j]] * get(i, i) - temp[permutation[i]] * get(j, i),
                    temp.normalize(permutation[j]);
        fori(temp.n) temp.normalize(i);
        T mx = 0;
        fori(temp.n) mx = std::max(mx, abs(get(i, i)));
        fori(temp.n) temp[permutation[i]] *= mx / get(i, i);
        matrix ret(temp.n, temp.m, 0);
        fori(temp.n) ret[i] = temp[permutation[i]];
        temp = ret;
        return mx;
    }
};
//Igorjan

template<typename T = ll, T mod = MOD>
struct modular
{
    T value = 0;

    modular(){}
    modular(const modular& other) : value(other.value) {}
    modular operator=(const modular& other) { value = other.value; return *this; }
    template<typename T1> modular operator=(const T1& other) { value = other % mod; return *this; }
    template<typename T1> modular(T1 const& t) { if (t > mod) value = t % mod; else value = t; }
    modular& operator+=(modular const& t)       { value += t.value; if (value > mod) value -= mod; return *this; }
    modular& operator-=(modular const& t)       { value -= t.value; if (value < 0  ) value += mod; return *this; }
    modular& operator*=(modular const& t)       { value = (value * t.value) % mod; return *this; }
    modular  operator+ (modular const& t) const { return modular(*this) += t; }
    modular  operator- (modular const& t) const { return modular(*this) -= t; }
    modular  operator* (modular const& t) const { return modular(*this) *= t; }

    friend ostream& operator<<(ostream& os, modular const& m) { return os << m.value; }
    friend istream& operator>>(istream& is, modular& m) { return is >> m.value; }
};
//}}}

typedef modular<ll, MOD> num;
void run()
{
    ll n, m;
    readln(n, m);
    matrix<num> p(m, m, 0);
    vector<num> v(m--, 1);
    fori(m) p[i + 1][i] = 1;
    p[m][m] = p[0][m] = 1;
    writeln((v * (p ^ max(0ll, n - m))).back());
}

//{{{
int main()
{
#ifndef ONLINE_JUDGE
    double time = clock();
#endif
    ios_base::sync_with_stdio(false);
//    freopen(FILENAME".in", "r", stdin);
//    freopen(FILENAME".out", "w", stdout);
    run();
#ifndef ONLINE_JUDGE
    writeln("execution time =", (clock() - time) / CLOCKS_PER_SEC);
#endif
    return 0;
}

#define a _a
#define n _n
ttti   ostream&operator<<(ostream&os,vector<T>const&a);
ttt12i istream&operator>>(istream&is,pair<T1,T2>&a){return is>>a.first>>a.second;}
ttt12i ostream&operator<<(ostream&os,pair<T1,T2>const&a){return os<<a.first<<" "<<a.second;}
ttti   ostream&operator<<(ostream&os,vector<T>const&a){if(a.size())os<<a[0];else os<<"\n";fori1(a.size())os<<"\n "[is_fundamental<T>::value]<<a[i];return os;}
ttti   ostream&operator<<(ostream&os,valarray<T>const&a){if(a.size())os<<a[0];else os<<"\n";fori1(a.size())os<<"\n "[is_fundamental<T>::value]<<a[i];return os;}
ttti   istream&operator>>(istream&is,vector<T>&a){fori(a.size())is>>a[i];return is;}
ttti   istream&operator>>(istream&is,valarray<T>&a){fori(a.size())is>>a[i];return is;}
ttti void print(T&&a){cout<<" "<<a;}
ttti void priws(T&&a){cout<<a;}
ttti void read(T&a){cin>>a;} //}}}

/**
 *   author:  prakhar17252
 *   created: 19.02.2019 14:03:10
**/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

using ll = long long;
using ld = long double;
#define int ll

#define pb emplace_back
#define push emplace
#define mp make_pair
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define len(a) (int) a.size()
#define reset(a, val) memset(a, val, sizeof(a))
#define endl '\n'
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (auto &i : v) os << i << " "; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (auto &i : v) os << i << " "; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << " " << v.second; return os; }
template <class T, class S> ostream& operator << (ostream &os, const map<T, S> &v) { for (auto &i : v) os << "(" << i.first << "=>" << i.second << ") "; return os; }

#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
    template <class Arg1, class... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args) {
        const char* sep = strchr(names + 1, ',');
        cerr.write(names, sep - names) << " : " << arg1 << "  ";
        __f(sep + 1, args...);
    }
#else
#define trace(...)
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#endif // ifndef ONLINE_JUDGE

template <class T, class cmp = less<T>> using ordered_set = tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;

const ll mod = (int) 1e9 + 7;
const ll inf = (ll) 2e18;
const ll ninf = (ll) -2e18;

ll power(ll x, ll y, ll mod = inf) {
    if (y == 0) return 1LL;
    if (y % 2) return (x * power(x, y - 1, mod)) % mod;
    return power((x * x) % mod, y / 2, mod);
}

#define T ll
struct Matrix {
    int n, m;
    vector<vector<T>> mat;

    Matrix(const vector<vector<T>> _mat) : n(_mat.size()), m(_mat[0].size()), mat(_mat) {}
    Matrix(const int _n) : n(_n), m(_n), mat(vector<vector<T>>(_n, vector<T>(_n, 0))) {}
    Matrix(const int _n, const int _m) : n(_n), m(_m), mat(vector<vector<T>>(_n, vector<T>(_m, 0))) {}
    Matrix(const int _n, const int _m, const T _val) : n(_n), m(_m), mat(vector<vector<T>>(_n, vector<T>(_m, _val))) {}
    Matrix(const Matrix &o) : n(o.n), m(o.m), mat(o.mat) {}

    // Remove modulo for doubles
    Matrix operator + (const Matrix &o) const {
        assert(n == o.n && m == o.m);
        vector<vector<T>> temp_mat(n, vector<T>(m));
        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++)
                temp_mat[i][j] = (mat[i][j] + o.mat[i][j]) % mod;
        return Matrix(temp_mat);
    }

    Matrix operator + (const T &c) const {
        vector<vector<T>> temp_mat(n, vector<T>(m));
        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++)
                temp_mat[i][j] = (mat[i][j] + c) % mod;
        return Matrix(temp_mat);
    }

    Matrix operator - (const Matrix &o) const {
        assert(n == o.n && m == o.m);
        vector<vector<T>> temp_mat(n, vector<T>(m));
        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++)
                temp_mat[i][j] = (mat[i][j] - o.mat[i][j] + mod) % mod;
        return Matrix(temp_mat);
    }

    Matrix operator - (const T &c) const {
        vector<vector<T>> temp_mat(n, vector<T>(m));
        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++)
                temp_mat[i][j] = (mat[i][j] - c + mod) % mod;
        return Matrix(temp_mat);
    }

    Matrix operator * (const Matrix &o) const {
        assert(m == o.n);
        int new_n = n, new_m = o.m, col = m;
        vector<vector<T>> temp_mat(new_n, vector<T>(new_m, 0));
        for (int i = 0; i < new_n; i++)
            for (int k = 0; k < col; k++) {
                for (int j = 0; j < new_m; j++) {
                    temp_mat[i][j] += 1LL * mat[i][k] * o.mat[k][j];
                    while (temp_mat[i][j] >= mod * mod) {
                        temp_mat[i][j] -= mod * mod;
                    }
                }
            }
        for (int i = 0; i < new_n; i++)
            for (int j = 0; j < new_m; j++)
                if (temp_mat[i][j] >= mod)
                    temp_mat[i][j] %= mod;
        return Matrix(temp_mat);
    }

    Matrix operator * (const T &c) const {
        vector<vector<T>> temp_mat(n, vector<T>(m));
        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++)
                temp_mat[i][j] = (mat[i][j] * c) % mod;
        return Matrix(temp_mat);
    }

    Matrix operator / (const T &c) const {
        T modinv = ::power(c, mod-2, mod);
        vector<vector<T>> temp_mat(n, vector<T>(m));
        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++)
                temp_mat[i][j] = (mat[i][j] * modinv) % mod;    // divide for doubles
        return Matrix(temp_mat);
    }

    Matrix operator - () {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                mat[i][j] = -mat[i][j];
            }
        }

        return Matrix(mat);
    }

    Matrix power(ll y) {
        assert(n == m);
        Matrix x(*this), ans = Matrix::identity(n);
        while (y > 0) {
            if (y % 2) ans *= x;
            x *= x;
            y /= 2;
        }
        return ans;
    }

    static Matrix identity(const int _n) {
        vector<vector<T>> temp_mat(_n, vector<T>(_n, 0));
        for (int i = 0; i < _n; i++) {
            temp_mat[i][i] = 1;
        }
        return Matrix(temp_mat);
    }

    void fill(const T c) { mat = vector<vector<T>>(n, vector<T>(m, c)); }
    void clear() { mat = vector<vector<T>>(n, vector<T>(m, 0)); }

    Matrix& operator = (const Matrix &o) { mat = o.mat; n = o.n; m = o.m; return *this; }
    Matrix& operator += (const Matrix &o) { *this = (*this + o); return *this; }
    Matrix& operator += (const T &c) { *this = (*this + c); return *this; }
    Matrix& operator -= (const Matrix &o) { *this = (*this - o); return *this; }
    Matrix& operator -= (const T &c) { *this = (*this - c); return *this; }
    Matrix& operator *= (const Matrix &o) { *this = (*this * o); return *this; }
    Matrix& operator *= (const T &c) { *this = (*this * c); return *this; }
    Matrix& operator /= (const T &c) { *this = (*this / c); return *this; }
    vector<T>& operator [] (int n) { return mat[n]; }
    bool operator == (const Matrix &o) const { return mat == o.mat; }
    bool operator != (const Matrix &o) const { return mat != o.mat; }
};

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    time_t t1, t2;
    t1 = clock();

    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
        freopen("error.txt", "w", stderr);
    #endif

    int n, m;
    cin >> n >> m;
    Matrix f(m, 1, 1), mat(m, m);
    mat[0][0] = 1;
    mat[0][m-1] = 1;
    for (int i = 1; i < m; i++) {
        mat[i][i-1] = 1;
    }

    cout << (mat.power(n-m+1) * f)[0][0] << '\n';

    t2 = clock();
    #ifndef ONLINE_JUDGE
        cerr << endl << "time taken: " << (ld) (t2 - t1) / CLOCKS_PER_SEC << endl;
    #endif // ONLINE_JUDGE

    return 0;
}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(c)	c.begin(), c.end()
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define trace(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {cout << "\n";}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {cerr << *it << " : " << a << " | "; err(++it, args...);}

typedef long long int lli;
typedef long double ld;
typedef pair<lli, lli> plli;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pair<lli, lli> > vplli;
typedef vector<lli> vlli;
typedef vector<vlli> vvlli;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef tree <lli, null_type, less<lli>, rb_tree_tag, tree_order_statistics_node_update >ordered_set;

#define PI 3.141592653589793
#define mod (lli)(1000*1000*1000+7)

template<typename T> T gcd(T a, T b) { if (a == 0) return b; return gcd(b % a, a); }
template<typename T> T pow(T a, T b, lli m) {T ans = 1; while (b > 0) { if (b % 2 == 1) ans = ((ans % m) * (a % m)) % m; b /= 2; a = ((a % m) * (a % m)) % m; } return ans % m; }
const int N = 100010;

void add(lli& a, lli b) {
	a = (a % mod + b % mod) % mod;
}

lli sub(lli a, lli b) {
	a -= b;
	if (a < 0)	a += mod;
	return a;
}

lli mult(lli a, lli b) {
	return (((a % mod) * (b % mod)) % mod);
}

lli power(lli a, lli b) {
	lli v = pow(a, b, mod);
	return v;
}

void print(vvlli& arr) {
	for (int i = 0; i < arr.size(); i++) {
		for (int j = 0; j < arr.size(); j++) {
			cout << arr[i][j] << " \n"[j == arr.size() - 1];
		}
	}
}

void mult(vvlli& a, vvlli& b) {
	vvlli c(a.size(), vlli(b[0].size(), 0ll));
	for (int r = 0; r < a.size(); ++r) {
		for (int j = 0; j < b[0].size(); ++j) {
			for (int x = 0; x < b.size(); ++x) {
				c[r][j] += mult(a[r][x], b[x][j]);
				c[r][j] %= mod;
			}
		}
	}a=c;
}

void pow(vvlli& arr, lli n) {
	if (n <= 1) return;

	if (n & 1) {
		vvlli temp = arr;
		pow(arr, n / 2ll);
		mult(arr, arr);
		mult(arr, temp);
	} else {
		pow(arr, n / 2ll);
		mult(arr, arr);
	}
}

int main() {
	fio;
	lli n, m;
	cin >> n >> m;
	//take 1 or m
	// answer(n-1) + answer(n-m)
	if (n - m < 0) {
		// 1 1 1 1 1 1 1 1...
		cout << "1\n";
		return 0;
	}

	vvlli cof(m, vlli(m, 0ll));
	cof[0][0] = 1;
	cof[0][m - 1] = 1;
	for (int i = 1; i < cof.size(); i++) {
		cof[i][i - 1] = 1;
	}

	pow(cof, n - m + 1);
	lli ans = 0ll;
	for (int i = 0; i < m; i++) {
		ans = ans + cof[0][i];
		ans %= mod;
	}
	cout << ans << "\n";
}

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define int long long int
#define ld long double
#define F first
#define S second
#define pb push_back

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
new_data_set;

const int N=100005;
const int M=105;
const int mod=1e9+7;
int sz;

struct Mat
{
    int m[M][M];

    Mat()
    {
        memset(m, 0, sizeof m);
    }

    void eye()
    {
        for(int i=0; i<sz; i++)
            m[i][i] = 1;
    }

    Mat operator* (const Mat &a) const
    {
        Mat r;
        for(int i=0; i<sz; i++)
            for(int j=0; j<sz; j++)
                for(int k=0; k<sz; k++)
                    r.m[i][j] = (r.m[i][j] + m[i][k] * 1ll * a.m[k][j]) % mod;
        return r;
    }
};
int multiply(long e)
{
    Mat r, a;
    r.eye();
    a.m[0][0] = a.m[0][sz-1] = 1;
    for(int i=1; i<sz; i++)
        a.m[i][i-1] = 1;
    while(e)
    {
        if(e & 1)
            r = r * a;
        a = a * a;
        e >>= 1;
    }
    return r.m[0][0];
}

int32_t main()
{
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    // int t;
    // cin>>t;
    // while(t--)
    {
        int i,j,k,n,m,ans=0,cnt=0,sum=0;
        cin>>n>>m;
        sz=m;
        Mat a,e;
        e.eye();
        a.m[0][0]=1;a.m[0][m-1]=1;
        for(i=1;i<m;i++){
            a.m[i][i-1]=1;
        }
        while(n){
            if(n&1){
                e=e*a;
            }
            a=a*a;
            n/=2;
        }
        cout<<e.m[0][0];
    }
}

#include<bits/stdc++.h>
using namespace std;
#define Sheryang main
#define TYPE int
const int maxn=1e6+7;
typedef long long ll;
const int mod=1e9+7;
void Smax(TYPE &a,TYPE b){if(a<b) a=b;}
void Smin(TYPE &a,TYPE b){if(a>b) a=b;}
///#define getchar()(p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++)
///char buf[(1 << 21) + 1], *p1 = buf, *p2 = buf;
#define IO cin.tie(0),ios::sync_with_stdio(false);
#define pi acos(-1)
#define PII pair<ll,ll>
ll read(){ll c = getchar(),Nig = 1,x = 0;while(!isdigit(c) && c!='-')c = getchar();if(c == '-')Nig = -1,c = getchar();while(isdigit(c))x = ((x<<1) + (x<<3)) + (c^'0'),c = getchar();return Nig*x;}
#define read read()
/** keep hungry and keep calm! **/

struct mat{
    ll m[105][105];
};

int m;
const mat operator *(mat &a,mat &b){
    mat ans;
    for(int i=1;i<=m;i++){
        for(int j=1;j<=m;j++){
            ans.m[i][j]=0;
            for(int k=1;k<=m;k++){
                ans.m[i][j]+=a.m[i][k]*b.m[k][j];
                if(ans.m[i][j]>=mod) ans.m[i][j]%=mod;
            }
        }
    }
    return ans;
}

ll qpow(mat a,ll b){
    mat ans;
    for(int i=1;i<=m;i++){
        for(int j=1;j<=m;j++){
            ans.m[i][j]=(i==j);
        }
    }

    while(b){
        if(b&1) ans=ans*a;
        a=(a*a);b>>=1;
    }

    ll res=ans.m[1][1];
    for(int i=1;i<=m;i++){
        res+=ans.m[1][i];
        if(res>=mod) res-=mod;
    }
    return res;
}

int Sheryang(){

    ll n=read;
    m=read;

    if(n<m){
        return printf("1"),0;
    }else if(n==m){
        return printf("2"),0;
    }

    mat a;
    memset(a.m,0,sizeof(a.m));
    a.m[1][1]=1;a.m[1][m]=1;
    for(int i=2;i<=m;i++){
        a.m[i][i-1]=1;
    }

    printf("%lld\n",qpow(a,n-m));
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
typedef long long int LL;
typedef vector<vector<LL>> vv;
LL n,m;
vv mult(vv& a, vv& b){
	vv res;
	int midd=a[0].size();
	int nc=b.size();
	for(int i=0;i<m;i++) res.push_back(vector<LL>(nc,0));
	for(int i=0;i<m;i++){
		for(int j=0;j<nc;j++){
			for(int k=0;k<midd;k++){
				res[i][j]+=a[i][k]*b[k][j];
				if(res[i][j]>=MOD) res[i][j]%=MOD;
			}
		}
	}
	return res;
}
vector<vector<LL>> fast(vector<vector<LL>>& mat, LL p){
	vv product;
	vector<LL> tmp(m,0);
	for(int i=0;i<m;i++){
		product.push_back(tmp);
	}
	for(int i=0;i<m;i++) product[i][i]=1;
	while(p){
		if(p&1) product=mult(product,mat);
		mat=mult(mat,mat);
		p/=2;
	}
	return product;
}

int main(){
	cin>>n>>m;
	vector<vector<LL>> mat(m,vector<LL>(m,0));
	mat[0][0]=1;
	mat[0][m-1]=1;
	for(int i=1;i<m;i++) mat[i][i-1]=1;
	if(n<m){
		puts("1");
		return 0;
	}
	vv conf=fast(mat,n-m+1);
	LL ans=0;
	for(int i=0;i<m;i++){
		ans+=conf[0][i];
		if(ans>=MOD) ans%=MOD;
	}
	cout<<ans<<"\n";
}

#include <cstdio>
#include <cstring>

const int M = 100;
const int z = 1e9+7;

struct mat {
    int a[M][M];
    int n;

    mat(int n) {
        this->n = n;
        memset(a, 0, sizeof(a));
    }
};

mat mmul(mat &a, mat &b) {
    mat ret(a.n);
    for (int i = 0; i < a.n; i++) {
        for (int j = 0; j < a.n; j++) {
            for (int k = 0; k < a.n; k++) {
                ret.a[i][j] = (ret.a[i][j] + 1ll * a.a[i][k] * b.a[k][j]) % z;
            }
        }
    }
    return ret;
}

mat mfp(mat &a, long long x) {
    if (x == 0) {
        mat ret(a.n);
        for (int i = 0; i < ret.n; i++) {
            ret.a[i][i] = 1;
        }
        return ret;
    }
    if (x % 2 == 1) {
        mat t = mfp(a, x - 1);
        return mmul(a, t);
    }
    mat ret = mfp(a, x / 2);
    return mmul(ret, ret);
}

int main() {
    long long n;
    int m;
    scanf("%lld %d", &n, &m);

    mat b(m);
    for (int i = 0; i < m - 1; i++) {
        b.a[i][i+1] = 1;
    }
    b.a[m-1][0] = b.a[m-1][+m-1] = 1;

    mat rec = mfp(b, n - 1);

    int ans = rec.a[0][m-1];
    for (int i = 0; i < m; i++) {
        ans = (ans + rec.a[0][i]) % z;
    }

    printf("%d\n", ans);

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define forr(i, a, b) for(int i = (a); i < (int) (b); i++)
#define forn(i, n) forr(i, 0, n)
#define dforr(i, a, b) for(int i = (int)(b-1); i >= (a); i--)
#define dforn(i, n) dforr(i, 0, n)
#define db(v) cerr << #v << " = " << v << endl
#define pb push_back
#define sz(x) ((int)x.size())
#define fst first
#define snd second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
const int MAXN = -1, MOD = 1e9+7;

const int MAXM = 101;
struct Mat{
    int n, m;
    int vec[MAXM][MAXM];
    Mat(int n): n(n), m(n){
        forn(i, n)forn(j, n)vec[i][j] = i==j; }
    Mat(int n, int m): n(n), m(m){
        forn(i, n)forn(j, m)vec[i][j] = i==j; }
    int * operator[](int f){ return vec[f]; }
    const int * operator[](int f)const{ return vec[f]; }

    void DEB(){
        return;
        db(n); db(m);
        forn(i, n){
            forn(j, m)printf("%d ", vec[i][j]);
            puts("");
        }puts("");
    }
    Mat operator*(const Mat &iA) const{
//        if(m != iA.n){
//            db(m);
//            db(iA.n);
//            DEB();
//            iA.DEB();
//            assert(false);
//        }
        int t = iA.m;
        Mat A(t, m), ans(n, t);
        forn(i, t)forn(j, m)A[i][j] = iA[j][i];

        forn(i, n)forn(j, t){
            ans[i][j] = 0;
            forn(k, m)ans[i][j] = (ans[i][j] + (ll)vec[i][k]*A[j][k]%MOD)%MOD;
        }
        return ans;
    }
};
//Mat operator*(const Mat A, const Mat iB){
//    assert(A.m == iB.n);
//    int n = A.n, m = iB.m, t = A.m;
//    Mat B(m, t), ans(n, m);
//    forn(i, m)forn(j, t)B[i][j] = iB[j][i];
//
//    forn(i, n)forn(j, m){
//        ans[i][j] = 0;
//        forn(k, t)ans[i][j] = (ans[i][j] + (ll)A[i][k]*B[j][k]%MOD)%MOD;
//    }
//    return ans;
//}
Mat expmat(Mat A, ll e){
//    db(e);
    int n = A.n;
    Mat ans(n);
    while(e){
        if(e&1)ans = ans*A;
        A = A*A; e>>=1;
    }
    return ans;
}

ll n, m;

int main(){
//	freopen("input.txt", "r", stdin);
    while(scanf("%lld %lld", &n, &m) >= 1){
        Mat A(m), V(1, m);
        forn(i, m)A[i][i] = 0;
        forr(i, 1, m)A[i][i-1] = 1;
        A[0][m-1] = A[m-1][m-1] = 1;
        forn(i, m)V[0][i] = 1;
        A.DEB();
        V.DEB();

        Mat T = V*expmat(A, n);
        printf("%d\n", T[0][0]);
	}
	return 0;
}

#include <algorithm>
#include <climits>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

#ifndef TEST
#define endl '\n'
#endif
#define eps 1e-9

#define ZERO(a) memset(a, 0, sizeof(a))
#define COPY(src, dest) memcpy(dest, src, sizeof(src))

typedef long long int ll;

const ll MOD = 1000 * 1000 * 1000 + 7;
const int MAT_SIZE = 105;

template <typename T>
T add(T a, T b) {
  T c = a + b;
  if (c > MOD) return c - MOD;
  return c;
}
template <typename T>
T mul(T a, T b) {
  T c = a * b;
  if (c > MOD) return c % MOD;
  return c;
}

template <typename T>
class Matrix {
 public:
  T data[MAT_SIZE][MAT_SIZE];
  int n, m;

  Matrix(int a, int b);
  Matrix(const Matrix<T> &A);
  Matrix<T> operator*(const Matrix<T> &)const;
  Matrix<T> operator^(long long int) const;
};

template <typename T>
Matrix<T>::Matrix(int a, int b) {
  if (a > MAT_SIZE || b > MAT_SIZE) {
    cerr << "Oversized matrix" << endl;
    exit(1);
  }
  n = a;
  m = b;
  ZERO(data);
}

template <typename T>
Matrix<T>::Matrix(const Matrix<T> &A) {
  n = A.n;
  m = A.m;
  COPY(A.data, data);
}

template <typename T>
Matrix<T> Matrix<T>::operator*(const Matrix<T> &b) const {
  Matrix<T> c(this->n, b.m);
  if (this->m != b.n) {
    cerr << "non compatible matrix multiplication\n";
    return c;
  }
  for (int i = 0; i < c.n; i++) {
    for (int j = 0; j < c.m; j++) {
      for (int k = 0; k < this->m; k++) {
        c.data[i][j] = add(c.data[i][j], mul(this->data[i][k], b.data[k][j]));
      }
    }
  }
  return c;
}

template <typename T>
Matrix<T> Matrix<T>::operator^(long long int pow) const {
  if (this->n != this->m) {
    cerr << "can't square non-square matrix\n";
    Matrix<T> a(1, 1);
    return a;
  }
  // Identity matrix initially
  Matrix<T> ret(this->n, this->n);
  for (int i = 0; i < this->n; i++) {
    for (int j = 0; j < this->n; j++) {
      if (i == j) ret.data[i][j] = 1;
    }
  }

  // The even power of the matrix
  Matrix<T> a = (*this);

  while (pow > 0) {
    if (pow & 1) ret = ret * a;

    pow >>= 1;
    a = a * a;
  }
  return ret;
}

int main() {
#ifndef TEST
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cerr.setstate(ios_base::failbit);
#endif
  ll n, m;
  cin >> n >> m;
  Matrix<ll> A(1, m);
  Matrix<ll> M(m, m);
  cerr << "HELLO\n" << endl;
  for (int i = 0; i < m; i++) {
    A.data[0][i] = 1;
  }
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < m; j++) {
      M.data[j][i] = 0;
      if (j == i + 1) {
        M.data[j][i] = 1;
      }
    }
  }
  M.data[0][m - 1] = M.data[m - 1][m - 1] = 1;
  ll ret = (A * (M ^ n)).data[0][0];
  cout << ret << endl;
}

#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e17;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define RFOR(i, a, b) for(ll i = (a); i > b; i--)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define RREP(i, n) for(ll i = n-1; i > -1; i--)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define epb emplace_back

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}

const ll mod = 1000000007 ;

struct Matrix {
    vvl val;
    Matrix(ll n, ll m, ll x = 0) : val(n, vl(m, x)) {}
    void init(ll n, ll m, ll x = 0) {val.assign(n, vl(m, x));}
    ll size() const {return val.size();}
    inline vector<ll>& operator [] (ll i) {return val[i];}
};

Matrix operator * (Matrix A, Matrix B) {
    Matrix R(A.size(), B[0].size());
    ll modsq = 4*mod*mod;
    REP(i, A.size()) REP(j, A.size()) REP(k, A.size()){
        R[i][j] += A[i][k] * B[k][j];
        if(R[i][j]>modsq) R[i][j] %= mod;
    }
    REP(i, A.size()) REP(j, A.size()) R[i][j] %= mod;
    return R;
}

Matrix pow(Matrix A, ll n) {
    Matrix R(A.size(), A.size());
    REP(i, A.size()) R[i][i] = 1;
    while (n > 0) {
        if (n & 1) R = R * A;
        A = A * A;
        n >>= 1;
    }
    return R;
}

ll N, M;

void prepare(Matrix& mat){
    REP(i, M) REP(j, M){
        if(i == 0){
            if(j == 0 || j == M-1) mat[i][j] = 1;
        }
        else if(i == j+1){
            mat[i][j] = 1;
        }
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> N >> M;
    auto mat = Matrix(M, M);
    prepare(mat);
    auto matN = pow(mat, N-(M-1));

    ll ans = 0;
    REP(i, M) ans += matN[0][i];
    cout << ans%mod << endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;

#define fastio          ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define pf              push_front
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define vvi             vector< vector<int> >
#define set             set<int>
#define mii             map<int,int>
#define pqbig           priority_queue<int>
#define pqsmall         priority_queue<int,vi,greater<int> >
#define sze             200005
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define pr(x);          for(auto el : x) cout<<el<<' '; cout<<'\n';
#define mk(arr,rw,type) type *arr=new type[rw];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1
#define argmax(beg,end) max_element(beg,end) - beg
#define argmin(beg,end) min_element(beg,end) - beg
#define mxit(v)         max_element(v.begin(),v.end())
#define mnit(v)         min_element(v.begin(),v.end())
#define MAX             101 //Haha

int pwmd(int a,int n)
{
    if(!n)
        return 1;
    int pt = pwmd(a,n/2);
    pt*=pt,pt%=mod;
    if(n&1)
        pt*=a,pt%=mod;
    return pt;
}

void coder_pulkit_c()
{
    fastio;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}

void multiply(int a[MAX][MAX],int b[MAX][MAX],int maxr1,int maxc1,int maxr2,int maxc2){
    int ans[MAX][MAX];

    for(int i=1;i<=maxr1;++i){
        for(int j=1;j<=maxc2;++j){
            int tmp=0;
            for(int id=1;id<=maxr2;++id)
                tmp=(tmp+a[i][id]*b[id][j])%mod;
            ans[i][j]=tmp;
        }
    }

    for(int i=1;i<=maxr1;++i)
        for(int j=1;j<=maxc2;++j)
            a[i][j]=ans[i][j];
}

void power(int base[MAX][MAX],int k,int p){
    if(!p)
    {
        for(int i=1;i<=k;++i)
            for(int j=1;j<=k;++j)
                if(i==j)
                    base[i][j]=1;
                else
                    base[i][j]=0;
        return;
    }
    if(p==1)
        return;

    int tmp[MAX][MAX];

    for(int i=1;i<=k;++i)
        for(int j=1;j<=k;++j)
            tmp[i][j]=base[i][j];

    power(base,k,p/2);
    multiply(base,base,k,k,k,k);

    if(p%2==0)
        return;

    multiply(base,tmp,k,k,k,k);
}

int nthTerm(int b[MAX][MAX],int c[MAX][MAX],int k,int n){
    if(n<=k)
        return b[n][1]%mod;

    int T[MAX][MAX];

    for(int i=1;i<=k;++i)
        for(int j=1;j<=k;++j)
            if(i!=k)
                if(j==i+1)
                    T[i][j]=1;
                else
                    T[i][j]=0;
            else
                T[i][j]=c[k-j+1][1];

    power(T,k,max(0ll,n-k-1));

    multiply(T,b,k,k,k,1);

    int ans=0;

    for(int i=1;i<=k;++i)
        ans=(ans+T[i][1]*c[k-i+1][1])%mod;

    return ans;
}

int32_t main()
{
    coder_pulkit_c();
        int n,m; cin>>n>>m;
                int k = m;
                int b[MAX][MAX]={0};
                int c[MAX][MAX]={0};
                for(int i=1;i<k;++i)
                    b[i][1]=1;
                b[k][1] = 2;
                c[1][1] = 1;
                c[k][1] = 1;
                int term = n;
               int ans = nthTerm(b,c,k,term)%mod;
        cout<<ans<<'\n';
    return 0;
}

#include<bits/stdc++.h>
#define int long long
#define ll long long
#define pb emplace_back
#define mp make_pair
#define tci(v,i) for(auto i=v.begin();i!=v.end();i++)
#define all(v) v.begin(),v.end()
#define rep(i,start,lim) for(long long (i)=(start);i<(lim);i++)
#define revrep(i,n) for(long long i=n-1;i>=0;i--)
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define osit ostream_iterator<int> output (cout," ")
#define pv(x) copy(all(x),output)
#define pa(a) rep(i,0,sizeof(a)/sizeof(a[0]))cout<<a[i]<<" "
#define endl '\n'
#define f first
#define s second
#define PI 3.141592653589793
#define test int t;cin>>t; while(t--)
#define set0(x) memset(x,0,sizeof(x))
#define set1(x) memset(x,1,sizeof(x))
#define getarr(arr,n) int arr[n];rep(i,0,n)cin>>a[i]
#define getvec(vec,n) vi vec;int x;rep(i,0,n){cin>>x;vec.pb(x);}
#define dg(x) cout<<#x<<':'<<x<<endl;
#define dg2(x,y) cout<<#x<<':'<<x<<' '<<#y<<':'<<y<<endl;
#define dg3(x,y,z) cout<<#x<<':'<<x<<' '<<#y<<':'<<y<<' '<<#z<<':'<<z<<endl;
#define dg4(x,y,z,zz) cout<<#x<<':'<<x<<' '<<#y<<':'<<y<<' '<<#z<<':'<<z<<' '<<#zz<<':'<<zz<<endl;
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;
template<typename T> T gcd(T a,T b){if(a==0) return b; return gcd(b%a,a);}
vi b_v;void bin(unsigned int n) { if (n > 1) bin(n>>1); b_v.pb(n & 1); }
int isPowerof2(int x) { return (x && !(x & x-1)); }

const int mod=1e9+7;
int n,m;

void mult(vvi& A, vvi& B){
    int m = A.size();
    vvi C(m, vi(m, 0));
    for(int i=0; i<m; i++){
        for(int j=0; j<m; j++){
            for(int k=0; k<m; k++){
                C[i][j] += A[i][k] * B[k][j];
                C[i][j] %= mod;
            }
        }
    }
    A = C;
}

int32_t main(){
    boost;osit;
    cin>>n>>m;
    vvi A(m,vi(m,0));
    vvi X(m,vi(m,0));
    A[0][0]=1;
    A[0][m-1]=1;
    rep(i,1,m)A[i][i-1]=1;
    X[0][0]=1;
    while(n>0){
        if(n&1){
            n--;
            mult(X,A);
        }else{
            n/=2;
            mult(A,A);
        }
    }
    cout<<X[0][0];
    return 0;
}

#include<bits/stdc++.h>
#define pi acos(-1)
#define ll long long
#define pii pair<ll,ll>
#define debug(a) cout<<a<<'\n'
#define maxn 500009 /// Still trying to be one box
#define F first
#define S second
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define per(i, a, b) for(int i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
using namespace std;
const ll INF = 1e17 + 9;
const int MOC = 1e9 + 7;
int MOC2=MOC;
ll phi(ll n) {
    ll result = n;
    for (ll i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            while (n % i == 0)
                n /= i;
            result -= result / i;
        }
    }
    if (n > 1)
        result -= result / n;
    return result;
}

ll mult(ll a, ll b){
    return (a*b)%(MOC2);
}

ll fastpow(ll a,ll b){
    ll ans=1;
    for(; b > 0;b/=2){
        if(b&1) ans = mult(ans,a);
        a = mult(a,a);
    }
    return ans;
}

template <class T>
T fexp(T x, long long e) {
    T ans(1);
    for(; e > 0; e /= 2) {
        if(e & 1) ans = ans * x;
        x = x * x;
    }
    // cout<<ans.val<<endl;
    return ans;
}

template <const int mod = MOC>
struct modBase {
    modBase(int v = 0) : val(v) {}
    int val;
    void operator += (modBase<mod> o) { *this = *this + o; }
    void operator -= (modBase<mod> o) { *this = *this - o; }
    void operator *= (modBase<mod> o) { *this = *this * o; }
    modBase<mod> operator * (modBase<mod> o) {
        if(((long long) val * o.val % mod)<0)return ((long long) val * o.val % mod)+mod;
        else return ((long long) val * o.val % mod);
    }
    //modBase<mod> operator / (modBase<mod> o) { return *this * fexp(o, mod - 2); }
    modBase<mod> operator + (modBase<mod> o) {
        if((val + o.val >= mod ? val + o.val - mod : val + o.val)<0) return (val + o.val >= mod ? val + o.val - mod : val + o.val)+mod;
        else return (val + o.val >= mod ? val + o.val - mod : val + o.val);
    }
    modBase<mod> operator - (modBase<mod> o) { return val - o.val < 0 ? val - o.val + mod : val - o.val; }
};

template<const size_t n, const size_t m, class T = modBase<>>
struct Matrix {
    T v[n][m];

    Matrix(int d = 0) {
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < m; j++) {
                v[i][j] = T(0);
            }
            if(i < m) {
                v[i][i] = T(d);
            }
        }
    }

    template<size_t mm>
    Matrix<n, mm, T> operator *(Matrix<m, mm, T> &o) {
        Matrix<n, mm, T> ans;
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < mm; j++) {
                for(int k = 0; k < m; k++) {
                    ans.v[i][j] = ans.v[i][j] + v[i][k] * o.v[k][j];
                }
            }
        }
        return ans;
    }
};
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,m;
    cin>>n>>m;
    Matrix<100,100> mat1(0);
    rep(i,0,m-1){
        mat1.v[i][i+1]=1;
    }
    mat1.v[m-1][0] = mat1.v[m-1][m-1] = 1;
    Matrix<100,1> ans1(0);
    rep(i,0,m-1)ans1.v[i][0]=1;
    ans1.v[m-1][0]=2;
    // cout<<ans1.v[0][0].val<<endl;
    ans1=fexp(mat1,max(n-m,0LL))*ans1;
    if(n>=m)cout<<ans1.v[m-1][0].val<<"\n";
    else cout<<ans1.v[n-1][0].val<<"\n";
    return 0;
}

// @subject:
// @diff:

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
std::mt19937_64 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());

#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define cl(x, v) memset((x), (v), sizeof(x))
#define gcd(x,y) __gcd((x),(y))

#ifndef ONLINE_JUDGE
  #define db(x) cerr << #x << " == " << x << endl
  #define dbs(x) cerr << x << endl
  #define _ << ", " <<
#else
  #define db(x) 42
  #define dbs(x) 42
#endif

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

const ld EPS = 1e-9, PI = acos(-1.);
const int INF = 0x3f3f3f3f, MOD = 1e9+7;
const int N = 1e5+5;

ll n, m;

struct t {
  int v;

  t() : v(0) {}
  t(int v) : v(v) {}
  inline t operator=(int i) { return *this = t{i}; }
  inline t operator+(t b) const { int x = v+b.v; return t { x >= MOD ? x-MOD : x }; }
  inline t operator-(t b) const { int x = v-b.v; return t { x <  0   ? x+MOD : x }; }
  inline t operator*(t b) const { int x = 1ll*v*b.v%MOD; return t { x }; }
};

struct mat {
  vector<vector<t>> v;

  mat(int s) {
    init(s);
  }

  void init(int s) {
    v = vector<vector<t>>(s, vector<t>(s));
    for (int i = 0; i < s; i++) v[i][i] = 1;
  }

  void clear(int s) {
    v = vector<vector<t>>(s, vector<t>(s));
  }
};

mat mul(const mat& a, const mat& b) {
  mat r(m);
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < m; j++) {
      t v;
      for (int k = 0; k < m; k++) {
        v = v + (a.v[i][k] * b.v[k][j]);
      }

      r.v[i][j] = v;
    }
  }
  return r;
}

mat fexp(mat a, ll b) {
  mat r(m);
  for (; b; b>>=1, a = mul(a,a)) if (b&1) r = mul(r,a);
  return r;
}

int main() {
  scanf("%lld%lld", &n, &m);
  if (n < m) return printf("1\n"), 0;

  mat a(m);
  a.clear(m);
  a.v[0][0] = 1; a.v[0][m-1] = 1;
  for (int i = 1; i < m; i++) a.v[i][i-1] = 1;

  mat b = fexp(a, n-m+1);

  t ans;
  for (int i = 0; i < m; i++) ans = ans + b.v[0][i];

  printf("%d\n", ans.v);

  return 0;
}

#include <bits/stdc++.h>

#define taskname ""
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define for0(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex <ld> cd;
typedef vector <cd> vcd;
typedef vector <int> vi;

template<class T> bool uin(T &a, T b)
{
    return a > b ? (a = b, true) : false;
}
template<class T> bool uax(T &a, T b)
{
    return a < b ? (a = b, true) : false;
}

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

const int maxM = 1e2 + 10;
const ll mod = 1e9 + 7;

ll tmp[maxM][maxM];

struct Matrix
{
    int n, m;
    vector <vector <ll>> s;
    Matrix() : n(0), m(0) {}
    Matrix(vector <vector <ll>>& a)
    {
        s = a;
        n = s.size();
        if (n > 0)
        {
            m = s[0].size();
        }
    }
    Matrix(int n, int m) : n(n), m(m)
    {
        s = vector <vector <ll>>(n, vector <ll>(m));
    }
    vector <ll>& operator[](int i)
    {
        return s[i];
    }
    Matrix operator*(Matrix a)
    {
        int p = a.m;
        vector <vector <ll>>& t = a.s;
        //Transpose
        for0(i, m)
        {
            for0(j, p)
            {
                tmp[j][i] = t[i][j];
            }
        }
        Matrix r(n, p);
        for0(i, n)
        {
            for0(j, p)
            {
                ll sum = 0;
                for0(k, m)
                {
                    sum += s[i][k] * tmp[j][k] % mod;
                }
                r[i][j] = sum % mod;
            }
        }
        return r;
    }
};

Matrix power(Matrix a, ll b)
{
    //square matrix
    int n = a.n;
    Matrix r(n, n);
    for0(i, n)
    {
        r[i][i] = 1;
    }
    while (b)
    {
        if (b & 1)
        {
            r = r * a;
        }
        b >>= 1;
        a = a * a;
    }
    return r;
}

ll n;
int m;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> m;
    if (n < m)
    {
        cout << 1;
        return 0;
    }
    Matrix ans(1, m), b(m, m);
    for0(j, m)
    {
        ans[0][j] = 1;
    }
    for1(i, m - 1)
    {
        b[i][i - 1] = 1;
    }
    b[0][m - 1] = b[m - 1][m - 1] = 1;
    ans = ans * power(b, n - m + 1);
    cout << ans[0][m - 1];
    return 0;
}

/**
 *   author:  prakhar17252
 *   created: 18.02.2019 23:34:40
**/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

using ll = long long;
using ld = long double;
#define int ll

#define pb emplace_back
#define push emplace
#define mp make_pair
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define len(a) (int) a.size()
#define reset(a, val) memset(a, val, sizeof(a))
#define endl '\n'
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (auto &i : v) os << i << " "; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (auto &i : v) os << i << " "; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << " " << v.second; return os; }
template <class T, class S> ostream& operator << (ostream &os, const map<T, S> &v) { for (auto &i : v) os << "(" << i.first << "=>" << i.second << ") "; return os; }

#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
    template <class Arg1, class... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args) {
        const char* sep = strchr(names + 1, ',');
        cerr.write(names, sep - names) << " : " << arg1 << "  ";
        __f(sep + 1, args...);
    }
#else
#define trace(...)
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#endif // ifndef ONLINE_JUDGE

template <class T, class cmp = less<T>> using ordered_set = tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;

const ll mod = (int) 1e9 + 7;
const ll inf = (ll) 2e18;
const ll ninf = (ll) -2e18;

ll power(ll x, ll y, ll mod = inf) {
    if (y == 0) return 1LL;
    if (y % 2) return (x * power(x, y - 1, mod)) % mod;
    return power((x * x) % mod, y / 2, mod);
}

#define T int
struct Matrix {
    int n, m;
    vector<vector<T>> mat;

    Matrix(const vector<vector<T>> _mat) : n(_mat.size()), m(_mat[0].size()), mat(_mat) {}
    Matrix(const int _n) : n(_n), m(_n), mat(vector<vector<T>>(_n, vector<T>(_n, 0))) {}
    Matrix(const int _n, const int _m) : n(_n), m(_m), mat(vector<vector<T>>(_n, vector<T>(_m, 0))) {}
    Matrix(const Matrix &o) : n(o.n), m(o.m), mat(o.mat) {}

    // Remove modulo for doubles
    Matrix operator + (const Matrix &o) {
        assert(n == o.n && m == o.m);
        vector<vector<T>> temp_mat(n, vector<T>(m));
        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++)
                temp_mat[i][j] = (mat[i][j] + o.mat[i][j]) % mod;
        return Matrix(temp_mat);
    }

    Matrix operator + (const T &c) {
        vector<vector<T>> temp_mat(n, vector<T>(m));
        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++)
                temp_mat[i][j] = (mat[i][j] + c) % mod;
        return Matrix(temp_mat);
    }

    Matrix operator - (const Matrix &o) {
        assert(n == o.n && m == o.m);
        vector<vector<T>> temp_mat(n, vector<T>(m));
        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++)
                temp_mat[i][j] = (mat[i][j] - o.mat[i][j] + mod) % mod;
        return Matrix(temp_mat);
    }

    Matrix operator - (const T &c) {
        vector<vector<T>> temp_mat(n, vector<T>(m));
        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++)
                temp_mat[i][j] = (mat[i][j] - c + mod) % mod;
        return Matrix(temp_mat);
    }

    Matrix operator * (const Matrix &o) {
        assert(m == o.n);
        int new_n = n, new_m = o.m, col = m;
        vector<vector<T>> temp_mat(new_n, vector<T>(new_m, 0));
        for (int i = 0; i < new_n; i++)
            for (int j = 0; j < new_m; j++)
                for (int k = 0; k < col; k++)
                    temp_mat[i][j] = (temp_mat[i][j] + mat[i][k] * o.mat[k][j]) % mod;
        return Matrix(temp_mat);
    }

    Matrix operator * (const T &c) {
        vector<vector<T>> temp_mat(n, vector<T>(m));
        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++)
                temp_mat[i][j] = (mat[i][j] * c) % mod;
        return Matrix(temp_mat);
    }

    Matrix operator / (const T &c) {
        T modinv = ::power(c, mod-2, mod);
        vector<vector<T>> temp_mat(n, vector<T>(m));
        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++)
                temp_mat[i][j] = (mat[i][j] * modinv) % mod;    // divide for doubles
        return Matrix(temp_mat);
    }

    Matrix power(int y) {
        assert(n == m);
        Matrix x(*this), ans = Matrix::identity(n);
        while (y > 0) {
            if (y % 2) ans *= x;
            x *= x;
            y /= 2;
        }
        return ans;
    }

    static Matrix identity(int _n) {
        vector<vector<T>> temp_mat(_n, vector<T>(_n, 0));
        for (int i = 0; i < _n; i++) {
            temp_mat[i][i] = 1;
        }
        return Matrix(temp_mat);
    }

    void fill(T &c) { mat = vector<vector<T>>(n, vector<T>(m, c)); }
    void clear() { mat = vector<vector<T>>(n, vector<T>(m, 0)); }

    void operator = (const Matrix &o) { mat = o.mat; }
    void operator += (const Matrix &o) { (*this) = ((*this) + o); }
    void operator += (const T &c) { (*this) = ((*this) + c); }
    void operator -= (const Matrix &o) { (*this) = ((*this) - o); }
    void operator -= (const T &c) { (*this) = ((*this) - c); }
    void operator *= (const Matrix &o) { (*this) = ((*this) * o); }
    void operator *= (const T &c) { (*this) = ((*this) * c); }
    void operator /= (const T &c) { (*this) = ((*this) / c); }
    bool operator == (const Matrix &o) { return mat == o.mat; }
    bool operator != (const Matrix &o) { return mat != o.mat; }
};

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    time_t t1, t2;
    t1 = clock();

    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
        freopen("error.txt", "w", stderr);
    #endif

    int n, m;
    cin >> n >> m;
    vector<vector<int>> f(m, vector<int>(1, 1));
    vector<vector<int>> mat(m, vector<int>(m, 0));
    mat[0][0] = 1;
    mat[0][m-1] = 1;
    for (int i = 1; i < m; i++) {
        mat[i][i-1] = 1;
    }

    Matrix ans = (Matrix(mat).power(n-m+1) * Matrix(f));
    cout << ans.mat[0][0] << '\n';

    t2 = clock();
    #ifndef ONLINE_JUDGE
        cerr << endl << "time taken: " << (ld) (t2 - t1) / CLOCKS_PER_SEC << endl;
    #endif // ONLINE_JUDGE

    return 0;
}

#include <iostream>
#include <vector>

typedef long long ll;
ll MOD = 1e9 + 7;

typedef std::vector<std::vector<ll>> matrix;

matrix mul(const matrix& a, const matrix& b) {
    matrix result(a.size(), std::vector<ll>(b[0].size(), 0LL));

    for (size_t i = 0; i < a.size(); ++i) {
        for (size_t j = 0; j < b[0].size(); ++j) {
            ll sum = 0;
            for (size_t k = 0; k < b.size(); ++k) {
                sum += ((a[i][k] % MOD) * (b[k][j] % MOD)) % MOD;
            }
            result[i][j] = sum % MOD;
        }
    }

    return result;
}

matrix exp(const matrix& a, ll n) {
    if (n == 1) {
        return a;
    } else if (n % 2 == 1) {
        return mul(a, exp(a, n - 1));
    } else {
        matrix temp = exp(a, n / 2);
        return mul(temp, temp);
    }
}

ll n, m;

int main() {
    std::cin >> n >> m;

    if (m > n) {
        std::cout << 1;
        return 0;
    }

    matrix initial = matrix(m, std::vector<ll>(1, 1LL));
    matrix transition = matrix(m, std::vector<ll>(m, 0LL));
    transition[m - 1][0] = 1;
    transition[m - 1][m - 1] = 1;

    for (size_t i = 0; i < m - 1; ++i) {
        transition[i][i + 1] = 1;
    }

    matrix e = exp(transition, n - m + 1);

    matrix res = mul(e, initial);
    std::cout << res.back()[0] % MOD;
}

#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;
#define endl '\n'
#define ll long long
#define int long long
#define ld double
#define pii pair<int,int>
#define rand() abs((rand()<<15)|rand())
#define randll() abs(((long long)rand()<<30)|rand())
const int MOD = 1'000'000'007;

int n, m;
map<int,int> dp;

int solve(int seg) {
	if(seg < m) return 1;
	if(seg == m) return 2;
	auto it = dp.find(seg);
	if(it != dp.end()) return it->second;

	int mid1 = (seg-1)/2;
	int mid2 = seg/2;
	if(seg%2) mid1--,mid2++;

	int cur = solve(mid1+1) * solve(seg-mid2);
	cur %= MOD;

	for(int r = mid1+1, l = r-m+1; l < mid2; l++, r++) {
		if(l<0) continue;
		if(r>=seg) continue;
		int dif = cur;
		cur += solve(l)*solve((seg-1)-r);
		dif -= cur;
		dif *= -1;
		cur %= MOD;
	}
	return dp[seg]=cur;
}

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	long long seed;
	asm("rdtsc" : "=A"(seed));
	srand(seed);

	cin >> n >> m;
	cout << solve(n) << endl;

}

#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <cassert>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, a, n) for (int i = n - 1; i >= a; i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int, int> PII;
const ll mod = 1000000007;
ll powmod(ll a, ll b)
{
    ll res = 1;
    a %= mod;
    assert(b >= 0);
    for (; b; b >>= 1)
    {
        if (b & 1)
            res = res * a % mod;
        a = a * a % mod;
    }
    return res;
}
// head
ll _, n;
namespace linear_seq
{
const int N = 10010;
ll res[N], base[N], _c[N], _md[N];

vector<int> Md;
void mul(ll *a, ll *b, int k)
{
    rep(i, 0, k + k) _c[i] = 0;
    rep(i, 0, k) if (a[i]) rep(j, 0, k) _c[i + j] = (_c[i + j] + a[i] * b[j]) % mod;
    for (int i = k + k - 1; i >= k; i--)
        if (_c[i])
            rep(j, 0, SZ(Md)) _c[i - k + Md[j]] = (_c[i - k + Md[j]] - _c[i] * _md[Md[j]]) % mod;
    rep(i, 0, k) a[i] = _c[i];
}
int solve(ll n, VI a, VI b)
{ // a 系数 b 初值 b[n+1]=a[0]*b[n]+...
    //        printf("%d\n",SZ(b));
    ll ans = 0, pnt = 0;
    int k = SZ(a);
    assert(SZ(a) == SZ(b));
    rep(i, 0, k) _md[k - 1 - i] = -a[i];
    _md[k] = 1;
    Md.clear();
    rep(i, 0, k) if (_md[i] != 0) Md.push_back(i);
    rep(i, 0, k) res[i] = base[i] = 0;
    res[0] = 1;
    while ((1ll << pnt) <= n)
        pnt++;
    for (int p = pnt; p >= 0; p--)
    {
        mul(res, res, k);
        if ((n >> p) & 1)
        {
            for (int i = k - 1; i >= 0; i--)
                res[i + 1] = res[i];
            res[0] = 0;
            rep(j, 0, SZ(Md)) res[Md[j]] = (res[Md[j]] - res[k] * _md[Md[j]]) % mod;
        }
    }
    rep(i, 0, k) ans = (ans + res[i] * b[i]) % mod;
    if (ans < 0)
        ans += mod;
    return ans;
}
VI BM(VI s)
{
    VI C(1, 1), B(1, 1);
    int L = 0, m = 1, b = 1;
    rep(n, 0, SZ(s))
    {
        ll d = 0;
        rep(i, 0, L + 1) d = (d + (ll)C[i] * s[n - i]) % mod;
        if (d == 0)
            ++m;
        else if (2 * L <= n)
        {
            VI T = C;
            ll c = mod - d * powmod(b, mod - 2) % mod;
            while (SZ(C) < SZ(B) + m)
                C.pb(0);
            rep(i, 0, SZ(B)) C[i + m] = (C[i + m] + c * B[i]) % mod;
            L = n + 1 - L;
            B = T;
            b = d;
            m = 1;
        }
        else
        {
            ll c = mod - d * powmod(b, mod - 2) % mod;
            while (SZ(C) < SZ(B) + m)
                C.pb(0);
            rep(i, 0, SZ(B)) C[i + m] = (C[i + m] + c * B[i]) % mod;
            ++m;
        }
    }
    return C;
}
int gao(VI a, ll n)
{
    VI c = BM(a);
    c.erase(c.begin());
    rep(i, 0, SZ(c)) c[i] = (mod - c[i]) % mod;
    return solve(n, c, VI(a.begin(), a.begin() + SZ(c)));
}
}; // namespace linear_seq
ll dp[305];
int main()
{
    int m;
    scanf("%lld%d", &n, &m);
    vector<int> v;
    for (int i = 1; i <= m; i++)
        dp[i] = 1;
    for (int i = m; i <= 200 + m; i++)
        dp[i] = ((dp[i - 1] + dp[i - m]) % mod);
    for (int i = 1; i <= 200; i++)
        v.push_back(dp[i]);
    n++;
    //VI{1,2,4,7,13,24}
    printf("%lld\n", linear_seq::gao(v, n - 1) % mod);
    return 0;
}

#include "bits/stdc++.h"

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back
#pragma GCC optimize ("-O3")

using namespace std;

#define DEBUG_IS_VALID

#ifdef DEBUG_IS_VALID
#define DEB 1
#else
#define DEB 0
#endif
#define DUMPOUT cout
#define dump(...) if(DEB) DUMPOUT<<"  "<<#__VA_ARGS__<<" :["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl<<"    "; if(DEB) dump_func(__VA_ARGS__)
template<typename T1,typename T2>ostream& operator << (ostream& os, pair<T1,T2> p){cout << "(" << p.first << ", " << p.second << ")"; return os;}
template<typename T>ostream& operator << (ostream& os, vector<T>& vec) { os << "{"; for (int i = 0; i<vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : ", "); os << "}"; return os; }
template<typename T>ostream& operator << (ostream& os, set<T>& st){cout << "{"; for(auto itr = st.begin(); itr != st.end(); itr++) cout << *itr << (next(itr)!=st.end() ? ", " : ""); cout << "}"; return os;}
template<typename T1,typename T2>ostream& operator << (ostream& os, map<T1,T2> mp){cout << "{"; for(auto itr = mp.begin(); itr != mp.end(); itr++) cout << "(" << (itr->first) << ", " << (itr->second) << ")" << (next(itr)!=mp.end() ? "," : ""); cout << "}"; return os; }

void dump_func(){DUMPOUT << endl;}
template <class Head, class... Tail>void dump_func(Head&& head, Tail&&... tail){ DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...);}
template<class T> inline bool chmax(T& a,T const& b){if(a>=b) return false; a=b; return true;}
template<class T> inline bool chmin(T& a,T const& b){if(a<=b) return false; a=b; return true;}
void _main();
int main(){ cin.tie(0); ios::sync_with_stdio(false); _main(); return 0;}

using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

const int mod=1e9+7,INF=1<<29;
const double EPS=1e-5,PI=3.1415926535897932384626;
const ll lmod = 1e9+7,LINF=1LL<<59;

template<int MOD> struct ModInt {
    static const int Mod = MOD; unsigned x; ModInt() : x(0) { }
    ModInt(signed sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    ModInt(signed long long sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    int get() const { return (int)x; }
    ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; }
    ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }
    ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
    ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
    ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
    ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }
    ModInt inverse() const { long long a = x, b = MOD, u = 1, v = 0;
        while (b) { long long t = a / b; a -= t * b; std::swap(a, b); u -= t * v; std::swap(u, v); }
        return ModInt(u); }
    bool operator==(ModInt that) const { return x == that.x; }
    bool operator!=(ModInt that) const { return x != that.x; }
    ModInt operator-() const { ModInt t; t.x = x == 0 ? 0 : Mod - x; return t; }
};
template<int MOD> ostream& operator<<(ostream& st, const ModInt<MOD> a) { st << a.get(); return st; };
template<int MOD> ModInt<MOD> operator^(ModInt<MOD> a, unsigned long long k) {
    ModInt<MOD> r = 1; while (k) { if (k & 1) r *= a; a *= a; k >>= 1; } return r; }
template<typename T, int FAC_MAX> struct Comb { vector<T> fac, ifac;
    Comb(){fac.resize(FAC_MAX,1);ifac.resize(FAC_MAX,1); for(int i = 1; i < FAC_MAX; i++)fac[i]=fac[i-1]*i;
        ifac[FAC_MAX-1]=T(1)/fac[FAC_MAX-1];for(int i = FAC_MAX-2; i >= 1; i--)ifac[i]=ifac[i+1]*T(i+1);}
    T aPb(int a, int b) { if (b < 0 || a < b) return T(0); return fac[a] * ifac[a - b]; }
    T aCb(int a, int b) { if (b < 0 || a < b) return T(0); return fac[a] * ifac[a - b] * ifac[b]; }
    T nHk(int n, int k) { if (n == 0 && k == 0) return T(1); if (n <= 0 || k < 0) return 0;
        return aCb(n + k - 1, k); }}; // nHk = (n+k-1)Ck : n is separator

using mint =  ModInt<int(1e9+7)>;
using vm = vector<mint>;

struct Mat {
  vector<vector<ll>> v;
  Mat(int n):v(n,vector<ll>(n)){};
  Mat(const vector<vector<ll>>& v):v(v){};
};
Mat mulmat(Mat& a,Mat& b) {
  int n = a.v.size();
	ll mo2=4*lmod*lmod;
	int x,y,z; Mat r(n);
	rep(x,n) rep(y,n) r.v[x][y]=0;
	rep(x,n) rep(z,n) rep(y,n) {
		r.v[x][y] += a.v[x][z]*b.v[z][y];
		if(r.v[x][y]>mo2) r.v[x][y] -= mo2;
	}
	rep(x,n) rep(y,n) r.v[x][y]%=lmod;
	return r;
}

Mat powmat(ll p,Mat a) {
  int n = a.v.size();
	int i,x,y; Mat r(n);
	rep(x,n) rep(y,n) r.v[x][y]=0;
	rep(i,n) r.v[i][i]=1;
	while(p) {
		if(p%2) r=mulmat(r,a);
		a=mulmat(a,a);
		p>>=1;
	}
	return r;
}

void _main(){
  // int N; cin >> N ;
  // int N,K; cin >> N >> K ;
  // int a,b; cin >> a >> b ;
  ll N,M; cin >> N >> M ;
	if(N-M+1<0){
		cout << "1" << endl;
		return;
	}
  Mat A(M);
  A.v[0][0] = 1;
  A.v[0][M-1] = 1;
  rep(i,M-1) A.v[i+1][i] = 1;
  auto An = powmat(N-M+1,A);
  ll ans(0);
  rep(i,M) (ans += An.v[0][i]) %= lmod;
  cout << ans << endl;
}

#include<map>
#include<queue>
#include<cmath>
#include<bitset>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
inline ll read(){
	ll ans=0,fh=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-') fh=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
		ans=(ans<<1)+(ans<<3)+ch-'0',ch=getchar();
	return ans*fh;
}
const int P=1e9+7;
struct node{
	ll a[110][110];
}p,tmp;
ll n;
int m;
inline node cheng(node x,node y){
	node tmp;
	for(int i=0;i<=m;i++)
	for(int j=0;j<=m;j++){
		tmp.a[i][j]=0;
		for(int k=0;k<=m;k++)
			tmp.a[i][j]+=1ll*x.a[i][k]*y.a[k][j]%P;
		tmp.a[i][j]%=P;
	}
	return tmp;
}
node poww(node x,ll y){
	for(int i=0;i<=m;i++)
		tmp.a[i][i]=1;
	while(y){
		if(y&1) tmp=cheng(tmp,x);
		x=cheng(x,x),y>>=1;
	}
	return tmp;
}
int main(){
//	freopen("nh.in","r",stdin);
	//freopen("zhy.out","w",stdout);
	n=read(),m=read()-1;
	p.a[0][0]++,p.a[m][0]++;
	for(int i=1;i<=m;i++)
		p.a[i-1][i]++;
	p=poww(p,n);
	ll ans=p.a[0][0];
	printf("%I64d\n",ans);
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll n,m;
const ll MOD=1e9+7;

mat mul(mat a,mat b)
{
    mat ret;
    for(int i=0;i<a.size();i++)
    {
        vec c;
        for(int j=0;j<b[0].size();j++)
        {
            ll sum=0;
            for(int k=0;k<a[0].size();k++)
            	sum+=a[i][k]*b[k][j],sum%=MOD;
            c.push_back(sum);
        }
        ret.push_back(c);
    }
    return ret;
}

mat pw(mat a,ll b)
{
    if(b==1) return a;
	if(b&1)
		return mul(a,pw(mul(a,a),b/2));
    return pw(mul(a,a),b/2);
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n>>m;
	mat anw;
	vec cand;
	for(int i=0;i<m;i++)
	{
		if(i==0||i==m-1)
			cand.push_back(1);
		else
			cand.push_back(0);
	}
	anw.push_back(cand);
	for(int i=0;i<m-1;i++)
	{
		vec cd;
		for(int j=0;j<m;j++)
		{
			if(i==j)
				cd.push_back(1);
			else
				cd.push_back(0);
		}
		anw.push_back(cd);
	}
	anw=pw(anw,n);
	cout<<anw[0][0];
    return 0;
}

//BROWNIE TK

#include <bits/stdc++.h>
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ldb;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define pb push_back
#define popb pop_back()
#define pf push_front
#define popf pop_front()
#define si size()
#define be begin()
#define en end()
#define all(v) v.be, v.en
#define le length()
#define mp make_pair
#define mt make_tuple
#define acc(v) accumulate(all(v),0)
#define F first
#define S second

#define forz(i, n) for (int i = 0; i < n; i++)
#define forzm(i, m, n) for (int i = m; i < n; i++)
#define rforz(i, n) for (int i = n - 1; i >= 0; i--)
#define rforzm(i, m, n) for (int i = n - 1; i >= m; i--)
#define deci(n) fixed << setprecision(n)
#define high(n) __builtin_popcount(n)
#define highll(n) __builtin_popcountll(n)
#define parity(n) __builtin_parity(n)
#define ctz(n) __builtin_ctz(n)
#define lb lower_bound
#define ub upper_bound
#define er equal_range
#define maxe *max_element
#define mine *min_element
#define mod 1000000007
#define mod2 998244353
#define gcd __gcd
#define kira ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)

#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl

#define oset tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define osetlli tree<lli, null_type, less<lli>, rb_tree_tag, tree_order_statistics_node_update>
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set
#define ofk order_of_key
#define fbo find_by_order
using namespace std;

/*STD fucntions*/
lli power(lli x, lli y, lli p)
{
    lli res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        //y must be even now
        y = y >> 1; //y=y/2
        x = (x * x) % p;
    }
    return res;
}
lli modi(lli a, lli m)
{
    // fermat little thm where m is prime
    return power(a, m - 2, m);
}
/*CODE BEGINS*/
struct matrix
{
    vector <vector <lli>>m;
};
void msi(matrix &m,lli a,lli b)
{
    m.m.resize(a);
    forz(i,a)
       m.m[i].resize(b);
}
void minit(matrix &m,lli x)
{
    forz(i,m.m.size())
       forz(j,m.m[0].size())
           m.m[i][j]=x;
}
matrix mul(matrix m1,matrix m2)
{
    matrix m3;
    msi(m3,m1.m.size(),m2.m[0].size());
    forz(i,m3.m.size())
      {
          forz(j,m3.m[0].size())
          {    m3.m[i][j]=0;
               forz(k,m1.m[0].size())
                 m3.m[i][j]=(m3.m[i][j]+m1.m[i][k]*m2.m[k][j])%mod;
          }
      }
      return m3;
}
matrix mexp(matrix &mx,lli p)
{
   matrix res;
   msi(res,mx.m.size(),mx.m.size());
   minit(res,0);
   forz(i,mx.m.size())
      res.m[i][i]=1;
   while(p>0)
   {
     if(p&1)
       res=mul(res,mx);
     mx=mul(mx,mx);
     p=p>>1;
   }
   return res;
}
int main()
{
    kira;
    lli n,m;
    cin>>n>>m;
    matrix ans;
    msi(ans,m,m);
    minit(ans,0);
    ans.m[0][0]=1;
    ans.m[0][m-1]=1;
    for(int i=1;i<m;i++)
    {
        ans.m[i][i-1]=1;
    }
    ans=mexp(ans,n);
    cout<<(ans.m[0][0])%mod;
    return 0;
}

#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <iomanip>
#include <string>
#include <deque>
#include <stack>
#include <cmath>

using namespace std;

#define PB push_back
#define MP make_pair
#define f first
#define s second
#define FOR(i,a,b) for (int i = a; i < b; ++i)
#define RFOR(i, b, a) for (int i = b-1; i>=a; --i)
#define FILL(a, b) memset(a, b, sizeof a)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)a.size()

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<LL> VI;
typedef pair<LL, LL> PLL;

const int INF = 1000 * 1000 * 1000;
const LL LINF = 1LL * INF*INF;
const int MAX = 100010	;
const long double PI = acos(-1.);
const double EPS = 1e-6;
LL mod = 1000LL * 1000 * 1000 + 7;

struct matrix
{
	vector<VI> mtr;
	matrix(int n)
	{
		FOR(i,0,n)
		{
			VI tmp;
			FOR(j,0,n)
				tmp.PB(0LL);
			tmp[i]=1LL;
			mtr.PB(tmp);
		}
	}
	matrix(vector<VI> arr)
	{
		mtr = arr;
	}
	matrix operator%(LL mod)
	{
		FOR(i,0,SZ(mtr))
		{
			FOR(j,0,SZ(mtr))
			{
				mtr[i][j]%=mod;
			}
		}
		return mtr;
	}
	matrix operator*(matrix b)
	{
		matrix ans(SZ(mtr));
		FOR(i,0,SZ(mtr))
		{
			FOR(j,0,SZ(mtr))
			{
				ans.mtr[i][j]=0;
				FOR(k,0,SZ(mtr))
				{
//					cout<<"ok"<<SZ(mtr)<<endl;
					LL x = mtr[i][k];
//					cout<<i<<" "<<j<<endl;
					LL z = b.mtr[k][j];
					LL tmp =(x * z)%mod;
					ans.mtr[i][j] = (ans.mtr[i][j]+tmp)%mod;
				}
			}
		}
		return ans;
	}
};
matrix binpowmod(matrix m1, LL  pow)
{
	matrix ans(SZ(m1.mtr));
	while(pow)
	{
//		cout<<pow<<endl;
		if(pow&1)
			ans = (ans*m1);

		m1=(m1*m1);

		pow>>=1;
	}
	return ans%mod;
}

int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);
	ios_base::sync_with_stdio(0);
	LL n,m;
	cin >> n >> m;
	vector<VI> a(m);
	FOR(i,0,m)
	{
		a[i].resize(m);
		if(i)
		{
			a[i][i-1]=1;
		}
		else
		{
			a[i][0] = 1;
			a[i][m-1] = 1;
		}
	}
	matrix t(a);
	t = binpowmod(t,n);
	LL ans = 0;
//	FOR(i,0,m)
//		ans=(ans+t.mtr[0][i])%mod;
	ans=(ans+t.mtr[0][0])%mod;
	cout<<ans;
	return 0;
}

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define MAXN 105
#define Mod 1000000007
#define Int register int
using namespace std;
inline void Swap(LL &x,LL &y)
{
	LL Temp = x;
	x = y;
	y = Temp;
}
inline LL Min(LL x,LL y)
{
	return x < y ? x : y;
}
inline LL Max(LL x,LL y)
{
	return x > y ? x : y;
}
inline void read(LL &x)
{
	x = 0;
	LL f = 1;
	char s = getchar();
	while (s < '0' || s > '9')
	{
		if (s == '-')
			f = -1;
		s = getchar();
	}
	while (s >= '0' && s <= '9')
	{
		x = (x << 3) + (x << 1) + (s ^ 48);
		s = getchar();
	}
	x *= f;
}
struct Matrix
{
	LL n, m, c[MAXN][MAXN];
	Matrix(){memset(c, 0, sizeof c);}
	friend Matrix operator *(Matrix A,Matrix B)
	{
		Matrix Res;
		Res.n = A.n, Res.m = B.m;
		for (Int i = 1; i <= A.n; ++ i)
			for (Int j = 1; j <= A.m; ++ j)
				for (Int k = 1; k <= B.n; ++ k)
					Res.c[i][j] += A.c[i][k] * B.c[k][j] % Mod,
					Res.c[i][j] %= Mod;
		return Res;
	}
}A, B;
inline Matrix QuickPow(Matrix x,LL y)
{
	Matrix Temp;
	Temp.n = Temp.m = x.m;
	for (Int i = 1; i <= x.m; ++ i)
		Temp.c[i][i] = 1;
	while ( y )
	{
		if (y & 1)
			Temp = Temp * x;
		x = x * x;
		y /= 2;
	}
	return Temp;
}
int main()
{
	LL n, m;
	read( n ); read( m );
	if (n < m)
		return ! printf("1");
	A.n = 1, A.m = m;
	B.n = B.m = m;
	for (Int i = 1; i <= m; ++ i)
		A.c[1][i] = 1; // f[m - 1] ~ f[0] = 1
	B.c[1][1] = B.c[1][m] = 1;
	for (Int i = 2; i <= m; ++ i)
		B.c[i][i - 1] = 1;
	B = QuickPow(B, n - m + 1);
	A = A * B;
	printf("%lld", A.c[1][1]);
	return 0;
}
/*
dp[0][0] = 1
dp[i][j] : 用 i 颗魔法宝石得到 j 颗宝石的方案数
dp[i][j] = \sum dp[i - 1][j - (1 ~ m-1)]

似乎把题目理解错了：一颗魔法宝石只能选择不分或分成 m 颗 ……

那么直接定义 dp[i] : 得到体积为 i 的方案数
dp[i] = dp[i - 1] + dp[i - m]
边界为 dp[0] = 1

{dp[i - 1], dp[i - m]}
-> {dp[i] = dp[i - 1] + dp[i - m], dp[i + 1 - m] = dp[i - m] + dp[i + 1 - 2m]}
*/

#include <bits/stdc++.h>
using namespace std;

const long long MOD = 1e9 + 7;

struct matrix {
    vector<vector<long long>> m;

    matrix(int n): m(n, vector<long long>(n)) {}

    static matrix identity(int n) {
        matrix m(n);
        for (int i = 0; i < n; i++)
            m.m[i][i] = 1;
        return m;
    }

    matrix operator*(matrix &rhs) {
        assert(m.size() == rhs.m.size());
        matrix res(m.size());
        for (int i = 0; i < (int)m.size(); i++)
            for (int j = 0; j < (int)m.size(); j++)
                for (int k = 0; k < (int)m.size(); k++)
                    res.m[i][j] = (res.m[i][j] + m[i][k] * rhs.m[k][j]) % MOD;
        return res;
    }

    vector<long long> operator*(vector<long long> v) {
        assert(m.size() == v.size());
        vector<long long> res(v.size());
        for (int i = 0; i < (int)m.size(); i++)
            for (int j = 0; j < (int)m.size(); j++)
                res[i] = (res[i] + m[i][j] * v[j]) % MOD;
        return res;
    }

    matrix pow(long long x) {
        matrix res = identity(m.size()), a = *this;
        while (x) {
            if (x & 1) res = res * a;
            a = a * a;
            x >>= 1;
        }
        return res;
    }
};

long long n;
int m;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);

    cin >> n >> m;

    matrix tf(m);
    tf.m[0][0] = tf.m[0][m - 1] = 1;
    for (int i = 1; i < m; i++)
        tf.m[i][i - 1] = 1;
    tf = tf.pow(n);

    auto res = tf * vector<long long>(m, 1);

    cout << res.back() << "\n";

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll D = 105;
const ll mod = 1000000007;
struct Matrix{
    ll a[D][D];
    Matrix (){}
};
ll add(ll x,ll y){
    x += y;
    if(x >= mod){
        x -= mod;
    }
    return x;
}
ll mult(ll x,ll y){
    return (x*y)%mod;
}
Matrix operator * (Matrix a,Matrix b){
    Matrix ans;
    for(long i = 0; i < D; i++){
        for(long j = 0; j < D; j++){
            ans.a[i][j] = 0;
        }
    }
    for(long i = 0; i < D; i++){
        for(long k = 0; k < D; k++){
            for(long j = 0; j < D; j++){
                ans.a[i][j] += a.a[i][k]*b.a[k][j]%mod;
                ans.a[i][j] %= mod;
            }
        }
    }
    return ans;
}
Matrix mpow(Matrix a,ll p){
    Matrix ans;
    for(long i = 0; i < D; i++){
        ans.a[i][i] = 1;
    }
    while(p){
        if(p&1){
            ans = ans*a;
        }
        a = a*a;
        p >>= 1;
    }
    return ans;
}
int main(){
    ll n,m;
    cin >> n >> m;
    if(n < m){
        cout << "1" << endl;
        return 0;
    }
    if(n == m){
        cout << "2" << endl;
        return 0;
    }
    Matrix base;
    base.a[0][0] = 1;
    base.a[0][m-1] = 1;
    for(long i = 1; i < D; i++){
        base.a[i][i-1] = 1;
    }
    base = mpow(base,n-m);
    Matrix nesto;
    nesto.a[0][0] = 2;
    for(long i = 1; i < m; i++){
        nesto.a[i][0] = 1;
    }
    base = base*nesto;
    cout << base.a[0][0] << endl;
}

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef map<ll,ll> mll;
typedef vector<bool> vb;

#define y0 sdkfaslhagaklsldk
#define y1 aasdfasdfasdf
#define yn askfhwqriuperikldjk
#define j1 assdgsdgasghsf
#define tm sdfjahlfasfh
#define lr asgasgash
#define endl "\n"
#define prina(arr,dau,cuoi) FTB(mmczmp,dau,cuoi)cout<<arr[mmczmp]<<" ";cout<<endl;
#define debug cout<<"debug\n"
#define DEBUG(x) { cout << #x << " = "; cout << (x) << endl; }
#define pb push_back
#define pbg(ke,u,v) ke[u].pb(v);ke[v].pb(u);
#define fi first
#define se second
#define pi acos(-1.0)
#define lbnd(f,s,gt) lower_bound(f,s,gt)
#define ubnd(f,s,gt) upper_bound(f,s,gt)
#define all(s) s.begin(),s.end()
#define bitcount(n) __builtin_popcountll(n)
#define REP(N) for(ll asgardhaha=1;asgardhaha<=N;asgardhaha++)
#define FTB(i,a,b) for(ll i=a,_b=b;i<=_b;i++)
#define FT(i,a,b) for(ll i=a,_b=b;i<_b;i++)
#define FGB(i,a,b) for(ll i=a,_b=b;i>=_b;i--)
#define FG(i,a,b) for(ll i=a,_b=b;i>_b;i--)
/////////////////////////////////////////////

const int mod=1e9+7;
ll n,m,res;
vector<vi> gt;

vector<vi> nhan(vector<vi> a,vector<vi> b){
    ll n=a.size(),m=b.size(),k=b[0].size();
    vector<vi> res(n,vi(k,0));
    FT(i,0,n) FT(j,0,k){
        FT(g,0,m){
            res[i][j]+=a[i][g]*b[g][j];
            res[i][j]%=mod;
        }
    }
    return res;
}

vector<vi> pow(vector<vi> a,ll mu){
    if(mu==1) return a;
    if(mu&1) return nhan(pow(a,mu-1),a);
    return pow(nhan(a,a),mu/2);
}

void Solve(){
    cin>>n>>m;
    gt.resize(m,vi(m,0));
    if(n<m){
        cout<<1;
        return;
    }
    ll dau=1;
    while(dau<m){
        gt[dau-1][dau]=1;dau++;
    }
    gt[m-1][0]=gt[m-1][m-1]=1;
    gt=pow(gt,n-m+1);
    FT(i,0,m) res=(res+gt[m-1][i])%mod;
    cout<<res;
}

int main(){
    ios::sync_with_stdio(0);cin.tie(0);

    //freopen("1.in","r",stdin);
    //freopen("1.out","w",stdout);

    int Test_numbers=1;
    //cin>>Test_numbers;

    while(Test_numbers--) Solve();

    //cerr << "\nTime run: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";

	return 0;
}

#include<bits/stdc++.h>
using namespace std;
namespace Flandre_Scarlet
{
	#define int long long
	#define mod ((int)1e9+7)

	#define F(i,l,r) for(int i=l;i<=r;++i)
	#define D(i,r,l) for(int i=r;i>=l;--i)
	#define Fs(i,l,r,c) for(int i=l;i<=r;c)
	#define Ds(i,r,l,c) for(int i=r;i>=l;c)
	#define Tra(i,u) for(int i=G.Start(u);~i;i=G.Next(i))
	#define MEM(x,a) memset(x,a,sizeof(x))
	#define FK(x) MEM(x,0)

	class Matrix//square matrix
	{
	    #define N 110//changeable
	    private:
	        int a[N][N];
	    public:
	        //variable list
	        int n;//size
	        //initialization
	        Matrix()
	        {
	            memset(a,0,sizeof(a));
	            n=0;
	        }
	        Matrix(int _n)
	        {
	            memset(a,0,sizeof(a));
	            n=_n;
	        }
	        Matrix(int _n,int _x)
	        {_x%=mod;
	            n=_n;
	            for(int i=0;i<N;++i)
	            {
	                for(int j=0;j<N;++j)
	                {
	                    a[i][j]=_x;
	                }
	            }
	        }

	        //get value
	        int* operator[](int i)
	        {
	            return *(a+i);
	        }

	        //set value
	        void Set(int x)
	        {x%=mod;
	            for(int i=0;i<N;++i)
	            {
	                for(int j=0;j<N;++j)
	                {
	                    a[i][j]=x;
	                }
	            }
	        }
	        void Identity()
	        {
	            memset(a,0,sizeof(a));
	            for(int i=0;i<N;++i)
	            {
	                a[i][i]=1;
	            }
	        }
	        #undef N //110
	};
	Matrix operator*(Matrix x,Matrix y)
	{
	    Matrix ans(x.n,0);
	    int n=ans.n;
	    F(i,1,n) F(j,1,n)
	    {
	    	if (x[i][j])
	    	{
	    		F(k,1,n)
	    		{
	    			ans[i][k]+=x[i][j]*y[j][k]%mod;
	                if (ans[i][k]>=mod) ans[i][k]-=mod;
	    		}
	    	}
	    }
	    return ans;
	}
	Matrix operator^(Matrix x,int p)
	{
	    Matrix ans(x.n,1);
	    ans.Identity();
	    while(p)
	    {
	        if (p&1) ans=ans*x;
	        x=x*x,p>>=1;
	    }
	    return ans;
	}

	int n,m;
	void Input()
	{
		cin>>n>>m;
	}

	void Soviet()
	{
		if (n<m)
		{
			puts("1");
			return;
		}

		Matrix Trans(m,0);
		Matrix Init(m,0);

		F(i,2,m)
		{
			Init[i][1]=1;
		}
		Init[1][1]=2;

		Trans[1][1]=Trans[1][m]=1;
		F(i,2,m) Trans[i][i-1]=1;

		Matrix Answer=(Trans^(n-m))*Init;
		printf("%lld\n",Answer[1][1]);
	}
	void IsMyWife()
	{
		Input();
		Soviet();
	}
	#undef int //long long
}
int main()
{
	Flandre_Scarlet::IsMyWife();
	getchar();getchar();
	return 0;
}

#include <iostream>
#include <cstring>
#include <cassert>
#include <random>
#include <algorithm>
#include <chrono>
#include <vector>
#define ull unsigned long long
#define ll long long

const int n = 100;
const ull MOD = 1000000007L;

#define I(j,i) ((j)*n + (i))

//unsigned int gA[n*n];
//unsigned int gC[n*n];

void mult(unsigned int * __restrict__ A, unsigned int * __restrict__ B, unsigned int * __restrict__ C)
{
    static ull buf[n];

    for (int j=0; j<n; ++j)
    {
        std::fill(buf,buf+n,0);
        int k = 0;
        for (; k+42<=n; k+=42)
        {
            for (int _k=k; _k<k+42; ++_k)
                for (int i=0; i<n; ++i)
                    buf[i] += (ull)A[I(_k,i)]*B[I(j,_k)];
            for (int i=0; i<n; ++i)
                buf[i] %= MOD;
        }
        for (; k<n; ++k)
            for (int i=0; i<n; ++i)
                buf[i] += (ull)A[I(k,i)]*B[I(j,k)];
        for (int i=0; i<n; ++i)
            C[I(j,i)] = buf[i]%MOD; // TODO should be C!!!
    }
}

void mult2(unsigned int * __restrict__ A, unsigned int * __restrict__ B)
{
    static ull buf2[n];
    std::fill(buf2,buf2+n,0);
    int k = 0;
    for (; k+18<=n; k+=18)
    {
        for (int _k=k; _k<k+18; ++_k)
            for (int i=0; i<n; ++i)
                buf2[i] += (ull)A[I(_k,i)]*B[_k];
        for (int i=0; i<n; ++i)
            buf2[i] %= MOD;
    }
    for (; k<n; ++k)
        for (int i=0; i<n; ++i)
            buf2[i] += (ull)A[I(k,i)]*B[k];
    for (int i=0; i<n; ++i)
        B[i] = buf2[i]%MOD;
}

void power(unsigned int *A, unsigned int *B, ull m)
{
    if (m==0)
        return;
    static unsigned int outM[n*n];
    while (m>10)
    {
        if (m&1)
        {
            mult2(A,B);
        }
        mult(A,A,outM);
        std::copy(outM,outM+n*n,A);
        m/=2;
    }
    while (m)
    {
        mult2(A,B);
        --m;
    }
}

int main()
{
    ll N;
    int m;
    std::cin >> N >> m;

    auto A = new unsigned int[n*n];
    auto B = new unsigned int[n];

    memset(A,0,4*n*n);
    memset(B,0,4*n);
    for (int i=0; i<m-1; ++i)
        A[I(i,i+1)] = 1;
    A[I(0,0)] = 1;
    A[I(m-1,0)] = 1;

    for (int i=0;i<m;++i)B[i] = 1;

    power(A,B,N);
    std::cout << B[m-1] << std::endl;
}

#include <bits/stdc++.h>

using namespace std;

#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define f first
#define s second
#define pb push_back

typedef long long ll;
typedef pair<int, int> ii;

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;

const int MOD = 1e9+7;

#define MODULAR true
template<typename T> struct matrix : vector<vector<T>> {
	int n, m;

	void print() {
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) cout << (*this)[i][j] << " ";
			cout << endl;
		}
	}

	matrix(int n_, int m_, bool ident = false) :
			vector<vector<T>>(n_, vector<T>(m_, 0)), n(n_), m(m_) {
		if (ident) {
			assert(n == m);
			for (int i = 0; i < n; i++) (*this)[i][i] = 1;
		}
	}
	matrix(const vector<vector<T>>& c) : vector<vector<T>>(c),
		n(c.size()), m(c[0].size()) {}
	matrix<T> operator+(matrix<T>& r) {
		matrix<T> M(n, m, 0);
		for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) {
			M[i][j] = (*this)[i][j] + r[i][j];
#if MODULAR
			if (M[i][j] >= MOD) M[i][j] -= MOD;
#endif
		}
		return M;
	}
	matrix<T> operator*(matrix<T>& r) {
		assert(m == r.n);
		matrix<T> M(n, r.m, 0);
		for (int i = 0; i < n; i++) for (int k = 0; k < m; k++)
			for (int j = 0; j < r.m; j++) {
				T add = (*this)[i][k] * r[k][j];
#if MODULAR
				M[i][j] += add%MOD;
				if (M[i][j] >= MOD) M[i][j] -= MOD;
#else
				M[i][j] += add;
#endif
			}
		return M;
	}
	matrix<T> operator^(ll e){
		assert(n == m);
		matrix<T> M(n, n, true);
		matrix<T> at = *this;
		while (e) {
			if (e&1) M = M*at;
			e >>= 1;
			at = at*at;
		}
		return M;
	}
	void fast_mult(matrix& v, ll e){
		auto M = *this;
		while (e) {
			if (e&1) v = M*v;
			e >>= 1;
			M = M*M;
		}
	}
};

int main() { _
	ll n; int m; cin >> n >> m;
	matrix<ll> M(m, m);
	M[0][0] = 1;
	M[0][m-1] = 1;
	for (int i = 1; i < m; i++) M[i][i-1] = 1;
	matrix<ll> v(m, 1);
	v[0][0] = 1;
	M.fast_mult(v, n);
	cout << v[0][0] << endl;
	exit(0);
}

#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double
#define sz(x) ((int)(x).size())

template <class... Args>
auto create(size_t n, Args&&... args) {
    if constexpr (sizeof...(args) == 1) {
        return vector(n, args...);
    } else {
        return vector(n, create(args...));
    }
}

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) ((void)42)
#endif

// Modular arithmetic
constexpr ll MOD = 1e9 + 7;
ll normalized(ll x, ll mod = MOD) { return ((x %= mod) < 0) ? x + mod : x; }
ll sum(ll a, ll b, ll mod = MOD) { return normalized(a + b, mod); }
ll diff(ll a, ll b, ll mod = MOD) { return normalized(a - b, mod); }
ll prod(ll a, ll b, ll mod = MOD) { return normalized(a * b, mod); }
ll modPow(ll base, ll exponent, ll mod = MOD) {
    if (exponent == 0) {
        return 1 % mod;
    }
    ll ret = modPow(base, exponent / 2, mod);
    ret = prod(ret, ret, mod);
    if (exponent % 2 == 1) {
        ret = prod(ret, base, mod);
    }
    return ret;
}
ll inv(ll x, ll mod = MOD) { return modPow(x, mod - 2, mod); }
ll quot(ll a, ll b, ll mod = MOD) { return prod(a, inv(b, mod), mod); }

// sz(a) by sz(a[0]) x sz(b) by sz(b[0]) -> sz(a) x sz(b[0])
vector<vector<int>> prod(const vector<vector<int>>& a, const vector<vector<int>>& b) {
    assert(sz(a[0]) == sz(b));
    auto ret = create(sz(a), sz(b[0]), 0);
    for (int i = 0; i < sz(ret); i++) {
        for (int k = 0; k < sz(a[0]); k++) {
            for (int j = 0; j < sz(ret[0]); j++) {
                ret[i][j] = sum(ret[i][j], prod(a[i][k], b[k][j]));
            }
        }
    }
    return ret;
}

vector<vector<int>> id(int n) {
    auto ret = create(n, n, 0);
    for (int i = 0; i < n; i++) {
        ret[i][i] = 1;
    }
    return ret;
}

vector<vector<int>> pow(const vector<vector<int>>& a, ll n) {
    if (n == 0) {
        return id(sz(a));
    }
    auto ret = pow(a, n / 2);
    ret = prod(ret, ret);
    if (n % 2 == 1) {
        ret = prod(ret, a);
    }
    return ret;
}

// last element can be a single or m.
// -> f(n) = f(n - 1) + f(n - m)

ll n;
int m;
vector<vector<int>> mat;

void solve() {
    cin >> n >> m;

    mat = create(m, m, 0);
    mat[0][0] = 1;
    mat[0][m - 1] = 1;
    for (int i = 1, j = 0; i < m; i++, j++) {
        mat[i][j] = 1;
    }

    auto f = create(m, 1, 1);
    auto finalMat = pow(mat, n - (m - 1));
    auto ans = prod(finalMat, f);

    int res = ans[0][0];

    cout << res << "\n";
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.setf(ios::fixed);
    cout.precision(15);

    int tt = 1;
    // cin >> tt;
    for (int i = 1; i <= tt; i++) {
        solve();
    }

    return EXIT_SUCCESS;
}

#include <bits/stdc++.h>
constexpr bool Interactive = false;

template <class T, class AddT, class MultT, T P>
struct ModNum {
  T val = 0;
  constexpr ModNum() = default;
  constexpr ModNum(T x) : val(x) {}
  template <class S> static constexpr ModNum Safe(S x) { return static_cast<T>( ((x%P)+P)%P ); }
  explicit constexpr operator T() const { return val; }

  constexpr bool operator==(ModNum rhs) const { return val == rhs.val; }
  constexpr bool operator!=(ModNum rhs) const { return val != rhs.val; }
  constexpr ModNum operator-() const { return (val == 0) ? (*this) : (P - val); }

  constexpr ModNum& operator+=(ModNum rhs) { return *this = Add(val, rhs.val); }
  constexpr ModNum& operator-=(ModNum rhs) { return *this = Sub(val, rhs.val); }
  constexpr ModNum& operator*=(ModNum rhs) { return *this = Mult(val, rhs.val); }
  constexpr ModNum& operator/=(ModNum rhs) { return *this *= rhs.Inverse(); }
  constexpr ModNum& operator++() { return *this += 1; }
  constexpr ModNum operator++(int) { ModNum old(*this); ++*this; return old; }
  constexpr ModNum& operator--() { return *this -= 1; }
  constexpr ModNum operator--(int) { ModNum old(*this); ++*this; return old; }

  template <class S>
  constexpr ModNum Pow(S ex) const {
    if (P == 1) return 0;
    if (ex < 0) return Pow(-ex).Inverse();
    ModNum result = 1;
    ModNum base(*this);
    while (ex > 0) {
      if (ex & 1) result *= base;
      ex >>= 1;
      base *= base;
    }
    return result;
  }
  constexpr ModNum Inverse() const { return Pow(P-2); }
  friend constexpr ModNum operator+(ModNum lhs, ModNum rhs) { return Add(lhs.val, rhs.val); }
  friend constexpr ModNum operator-(ModNum lhs, ModNum rhs) { return Sub(lhs.val, rhs.val); }
  friend constexpr ModNum operator*(ModNum lhs, ModNum rhs) { return Mult(lhs.val, rhs.val); }
  friend constexpr ModNum operator/(ModNum lhs, ModNum rhs) { return lhs * rhs.Inverse(); }

  private:
  static constexpr T Add(AddT lhs, AddT rhs) {
    auto sum = lhs+rhs;
    return (sum < P) ? sum : (sum - P);
  }
  static constexpr T Sub(AddT lhs, AddT rhs) {
    auto dif = lhs-rhs;
    return (dif >= 0) ? dif : (dif + P);
  }
  static constexpr T Mult(MultT lhs, MultT rhs) {
    return (lhs*rhs) % P;
  }
  friend std::ostream& operator<<(std::ostream& os, ModNum m) { return os << m.val; }
  friend std::istream& operator>>(std::istream& is, ModNum& m) { is >> m.val; return is; }
};
using Num = ModNum<int, int, long long, 1000000007>;

#pragma region
namespace Narut {
  struct {
    template <class T> auto operator<<(const T& t) const -> decltype((void) (std::cerr << t), *this) { std::cerr << "\033[0;31m" << t << "\033[0m"; return *this; }
    auto operator<< (std::ostream& (*f)(std::ostream&)) const { std::cerr << f; return *this; }
  } Cerr_red;
  #define CAN_(f) template <class, class=void> struct Can##f : std::false_type {}; template <class T> struct Can##f<T, decltype((void)f(std::declval<T&>())) > : std::true_type {};

  template <class T, class=void> struct IsIterable : std::false_type {}; template <class T> struct IsIterable<T, decltype((void)std::begin(std::declval<T&>()), (void)std::end(std::declval<T&>())) > : std::true_type {};

  template <decltype(auto) os, bool Flush = false, decltype(auto) PairSep = ' ', decltype(auto) PairEnd = '\n'>
  struct Writer {
    static constexpr char Sep = ' ', Sep2D = '\n';
    template <class, class = void> struct Osable : std::false_type {};
    template <class T> struct Osable<T, decltype((void)(os << std::declval<T&>())) > : std::true_type {};
    template <class Tuple, std::size_t... Is> static void TupleImpl(const Tuple& t, std::index_sequence<Is...>) { (void) (int[]) {0, (Write(PairSep), Write(std::get<Is+1>(t)), 0)... }; }
    template <class First, class... Ts> static void TupleImpl(const std::tuple<First, Ts...> &t) { Write(std::get<0>(t)); if constexpr (sizeof...(Ts) != 0) TupleImpl(t, std::index_sequence_for<Ts...>{}); }
    static void TupleImpl(const std::tuple<>&) {}
    template <class F, class S> static void PairImpl(const std::pair<F,S>& p) { Write(p.first), Write(PairSep), Write(p.second); }
    CAN_(PairImpl) CAN_(TupleImpl)
    template <class T> static void SepImpl (const T&) {
      if constexpr ( Osable<T>::value ) os << Sep;
      else if constexpr ( CanPairImpl<T>::value or CanTupleImpl<T>::value ) os << PairEnd;
      else os << Sep2D;
    }
    template <class T> static void IterableImpl(const T& t) {
      using std::begin, std::end;
      auto it = begin(t);
      if (it != end(t)) Write(*it++);
      while (it != end(t)) SepImpl(*it), Write(*it++);
    }
    template <class T> static void Write(const T& t) {
      if constexpr ( Osable<T>::value ) os << t;
      else if constexpr ( CanPairImpl<T>::value ) PairImpl(t);
      else if constexpr ( CanTupleImpl<T>::value ) TupleImpl(t);
      else if constexpr ( IsIterable<T>::value ) IterableImpl(t);
      else static_assert( IsIterable<T>::value, "No Matching Write Call!");
    }
    auto operator() () const { if constexpr (Flush) os << std::endl; else os << '\n'; return *this; }
    template <class First, class... Args> auto operator() (const First& f, const Args&... args) const { Write(f); (void) (int[]) {0, (Write(Sep), Write(args), 0)... }; return (*this)(); }
  };

  template <decltype(auto) is>
  struct Reader {
    template <class, class = void> struct Isable : std::false_type {}; template <class T> struct Isable<T, decltype((void)(is >> std::declval<T&>()))  > : std::true_type {};
    template <class T, class S> static void PairImpl(std::pair<T, S> &p) { Read(p.first); Read(p.second); }
    template <class Tuple, std::size_t... Is> static void TupleImpl(Tuple &t, std::index_sequence<Is...>) { (void) (int[]) {0, ( Read(std::get<Is>(t)), 0)... }; }
    template <class... Ts> static void TupleImpl(std::tuple<Ts...> &t) { TupleImpl(t, std::index_sequence_for<Ts...>{}); }
    template <class T> static void IterableImpl(T& t) { for (auto && x : t) Read(x); }
    CAN_(PairImpl) CAN_(TupleImpl)
    template <class T> static void Read (T& x) {
      if constexpr ( Isable<T>::value ) is >> x;
      else if constexpr ( CanPairImpl<T>::value ) PairImpl(x);
      else if constexpr ( CanTupleImpl<T>::value ) TupleImpl(x);
      else if constexpr ( IsIterable<T>::value ) IterableImpl(x);
      else static_assert ( IsIterable<T>::value, "No Matching Read!");
    }
    template <class T> void operator() (T& x) const { Read(x); }
    template <class T> void operator() (T& x, int n) const { x.resize(n); Read(x); }
    int operator() () const { return *this; }
    template <class T> operator T() const { T x; Read(x); return x; }
  };

  #ifdef NARUT_LOCAL
  Writer<(Cerr_red), false, ':', ' '> Debug;
  #else
  struct { template <class... Args> void operator()(Args&&...) const {} } Debug;
  #endif

  template <class T, int off=1> struct Offset : T {
    using T::T;
    Offset(const T& other) : T(other) {}
    Offset(T&& other) noexcept : T(std::move(other)) {}
    decltype(auto) operator[] (int i) { return T::operator[](i-off); }
    decltype(auto) operator[] (int i) const { return T::operator[](i-off); }
    decltype(auto) at (int i) { return T::at(i-off); }
    decltype(auto) at (int i) const { return T::at(i-off); }
  };

  template <template<class Elem, int S> class Base, class T, int NF, int... Ns>
  struct ArrRec : Base<ArrRec<Base, T, Ns...>, NF> {
    using Base<ArrRec<Base, T, Ns...>, NF>::Base;
    ArrRec& operator() (const T& t) { for (auto &a : *this) a(t); return *this; }
  };
  template <template<class Elem, int S> class Base, class T, int NF> struct ArrRec<Base, T, NF> : Base<T, NF> { using Base<T, NF>::Base; };

  template <class T, int N> struct ArrBase : std::array<T, N> {
    constexpr ArrBase() : std::array<T, N>{} {}
    constexpr ArrBase (std::initializer_list<T> il) { int i = 0; for (auto a : il) (*this)[i++] = a; }
    constexpr ArrBase(const std::array<T, N>& other) : std::array<T, N>(other) {}
    constexpr ArrBase(std::array<T, N>&& other) : std::array<T, N>(std::move(other)) {}
    ArrBase& operator() (const T& t) { this->fill(t); return *this; }
  };
  template <class T, int N> using ArrBase1 = Offset<ArrBase<T, N> >;

  template <class T, class = void> struct Greater { constexpr bool operator() (const T& lhs, const T& rhs) const { return rhs < lhs; } };
  template <class T> struct Greater<T, decltype((void)(std::declval<T&>() > std::declval<T&>()))> : std::greater<T> {};

  template <class T> using MaxPQ = std::priority_queue<T>;
  template <class T> using MinPQ = std::priority_queue<T, std::vector<T>, Greater<T> >;

  template <class T> void Unique(T& t) { t.erase(std::unique(std::begin(t), std::end(t)), std::end(t)); }
  struct Infinity { template <class T> operator T() const { return std::numeric_limits<T>::max(); } } Inf;
  struct BigNumber { operator int() const { return 0x3f3f3f3f;} operator long long() const{ return 0x3f3f3f3f3f3f3f3f; } } BigNum;

  struct IO {
    IO() {
      #ifdef NARUT_LOCAL
      if (!Interactive and !freopen("io/test.in", "r", stdin)) Debug("freopen failed");
      std::cerr << std::fixed << std::setprecision(10);
      #endif
      std::ios_base::sync_with_stdio(false);
      std::cin.tie(nullptr);
      std::cout << std::fixed << std::setprecision(10);
    }
  } FASTIO{} ;

  namespace Export {
    Writer<(std::cout), Interactive> Cout;
    Reader<(std::cin)> Cin;
    using Narut::Debug, Narut::MaxPQ, Narut::MinPQ, Narut::Offset;
    using Narut::Unique, Narut::Inf, Narut::BigNum;
    using ll = long long;
    using Pii = std::pair<int, int>; using Pll = std::pair<ll, ll>;
    template <class T> using Vec = std::vector<T>;
    template <class T> using Vec1 = Offset<std::vector<T> >;
    template <class T> using Vv = std::vector<std::vector<T> >;
    template <class T, int N, int... Ns> using Arr = ArrRec<Narut::ArrBase, T, N, Ns...>;
    template <class T, int N, int... Ns> using Arr1 = ArrRec<Narut::ArrBase1, T, N, Ns...>;
    using Vi = std::vector<int>; using Vi1 = Vec1<int>; using Vl = std::vector<ll>; using Vc = std::vector<char>;

    using std::abs, std::accumulate, std::acos, std::acosh, std::array, std::asin, std::asinh, std::atan, std::atanh, std::binary_search, std::bitset, std::cbrt, std::ceil, std::cin, std::cos, std::cosh, std::cout, std::deque, std::div, std::equal_range, std::exp, std::floor, std::gcd, std::get, std::getline, std::greater, std::hypot, std::iota, std::istringstream, std::lcm, std::ldexp, std::log, std::lower_bound, std::map, std::max, std::max_element, std::min, std::min_element, std::minmax, std::minmax_element, std::multimap, std::multiset, std::nearbyint, std::nth_element, std::next_permutation, std::optional, std::ostringstream, std::pair, std::partial_sum, std::pow, std::prev_permutation, std::queue, std::reverse, std::rint, std::round, std::runtime_error, std::set, std::shared_ptr, std::sin, std::sinh, std::sort, std::sqrt, std::stable_sort, std::stack, std::stod, std::stof, std::stoi, std::stol, std::stold, std::stoll, std::string, std::string_view, std::stringstream, std::swap, std::tan, std::tanh, std::to_string, std::trunc, std::tuple, std::unique, std::unique_ptr, std::unordered_map, std::unordered_multimap, std::unordered_multiset, std::unordered_set, std::upper_bound, std::vector;
  }
}
namespace std {
  template <template<class,int> class Base, class T, int NF> struct tuple_size<Narut::ArrRec<Base, T, NF> > : std::integral_constant<std::size_t, NF> {};
  template <std::size_t I, template<class,int> class Base, class T, int NF> struct tuple_element<I, Narut::ArrRec<Base, T, NF> > { using type = T; };
}

using namespace Narut::Export;
#define ALL(x)  std::begin(x), std::end(x)
#define RALL(x) std::rbegin(x), std::rend(x)
#define FOR(i,k,n)  for (int i = k; i < n; i++)
#pragma endregion

ll n;
int m;
using mat = vector<vector<Num> >;
vector<vector<Num> > M;
// vector<vector<Num> > res;

void Setup()
{
  vector<Num> cur(m);
  cur[0] = 1;
  cur.back() = 1;
  M.emplace_back(cur);
  for (int i = 1; i < m; i++) {
    cur[i]++;
    M.emplace_back(cur);
  }
}

auto Mult(const mat& A, const mat& B) {
  mat res(m, vector<Num>(m));
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < m; j++) {
      // res[i][j] = 0;
      for (int k = 0; k < m; k++)
        res[i][j] += A[i][k]*B[k][j];
    }
  }
  return res;
}

auto Mult2(const mat&A, const vector<Num>& B) {
  vector<Num> res(m);
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < m; j++) res[i] += A[i][j] * B[j];
  }
  return res;
}

auto Pow(const mat& A, ll p) {
  if (p == 1) return A;
  if (p & 1) {
    auto res = Pow(A, p/2);
    return Mult(A, Mult(res, res));
  } else {
    auto res = Pow(A, p/2);
    return Mult(res, res);
  }
}

auto Run()
{
  cin>>n>>m;
  Setup();

  // Debug(M);
  // res.assign(m, vector<Num>(m));
  auto np = n/m;

  vector<Num> res(m, 1);
  if (np > 0) {
    auto P = Pow(M, np);
    res = Mult2(P, res);
  }
  cout << res[n%m];
}

int main() {
  Run();
}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(c)	c.begin(), c.end()
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define trace(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define likely(x)       __builtin_expect((x),1)
#define unlikely(x)     __builtin_expect((x),0)

void err(istream_iterator<string> it) {cout << "\n";}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {cerr << *it << " : " << a << " | "; err(++it, args...);}

typedef unsigned long long int lli;
typedef long double ld;
typedef pair<lli, lli> plli;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pair<lli, lli> > vplli;
typedef vector<lli> vlli;
typedef vector<vlli> vvlli;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef tree <lli, null_type, less<lli>, rb_tree_tag, tree_order_statistics_node_update >ordered_set;

#define PI 3.141592653589793
#define mod (lli)(1000*1000*1000+7)
#define mod2 1000000014000000049L

template<typename T> T gcd(T a, T b) { if (a == 0) return b; return gcd(b % a, a); }
template<typename T> T pow(T a, T b, lli m) {T ans = 1; while (b > 0) { if (b % 2 == 1) ans = ((ans % m) * (a % m)) % m; b /= 2; a = ((a % m) * (a % m)) % m; } return ans % m; }
const int N = 100010;

void add(lli& a, lli b) {
	a=(a % mod + b % mod) % mod;
}

lli sub(lli a, lli b) {
	a -= b;
	if (a < 0)	a += mod;
	return a;
}

lli mult(lli a, lli b) {
	return (((a % mod) * (b % mod)) % mod);
}

lli power(lli a, lli b) {
	lli v = pow(a, b, mod);
	return v;
}

void print(vvlli& arr) {
	for (int i = 0; i < arr.size(); i++) {
		for (int j = 0; j < arr.size(); j++) {
			cout << arr[i][j] << " \n"[j == arr.size() - 1];
		}
	}
}

// ans = a*b
void mult(vvlli& ans, vvlli& a, vvlli& b) {
	vvlli c(a.size(), vlli(b[0].size(), 0ll));
    for (int r = 0; r < a.size(); ++r) {
		int x = 0;
		for (;x+18 <= a[0].size(); x+=18) {
            for (int _x=x; _x<x+18; ++_x)
    		    for (int j = 0; j < b[0].size(); ++j)
    				c[r][j]+= a[r][_x]*b[_x][j];
    		for (int j = 0; j < b[0].size(); ++j)
				c[r][j]%=mod;
		}
		for (;x < a[0].size(); ++x)
		    for (int j = 0; j < b[0].size(); ++j)
				c[r][j]+= a[r][x]*b[x][j];
	}

	for (int i = 0; i < a.size(); i++) {
		for (int j = 0; j < b[0].size(); j++) {
			ans[i][j] = c[i][j]%mod;
		}
	}
}

// Calc arr^n * arr2
void pow(vvlli& arr, vvlli& arr2, lli n) {
	if (n == 0) return;
	while (n>1)
	{
	    if (n&1)
	        mult(arr2,arr,arr2);
	    mult(arr,arr,arr);
	    n /= 2;
    }
    mult(arr2,arr,arr2);
}

int main() {
	fio;
	long long n;
	int m;
	cin >> n >> m;
	//take 1 or m
	// answer(n-1) + answer(n-m)
	if (n - m < 0) {
		// 1 1 1 1 1 1 1 1...
		cout << "1\n";
		return 0;
	}

	vvlli cof(m, vlli(m, 0ll));
	cof[0][0] = 1;
	cof[0][m - 1] = 1;
	for (int i = 1; i < cof.size(); i++) {
		cof[i][i - 1] = 1;
	}

	vvlli ans(m, vlli(1, 0ll));
	ans[0][0] = 1;

	pow(cof, ans, n);
	cout << ans[0][0] << "\n";
}

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define matrix vector<vector<ll> >
#define MOD 1000000007

ll m;

matrix mul(matrix A, matrix B)
{
    ll n = A.size(), k = A[0].size(), m = B[0].size();
    matrix C(n,vector<ll>(m));
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < m; j++)
        {
            for(int l = 0; l < k; l++)
            {
                C[i][j] = (C[i][j] + A[i][l]*B[l][j])%MOD;
            }
        }
    }
    return C;
}

matrix pow(matrix A, ll p)
{
    if(p == 1)return A;
    if(p%2==1)
    {
        return mul(A,pow(A,p-1));
    }
    else
    {
        matrix B = pow(A,p/2);
        return mul(B,B);
    }
}

ll fib(ll n)
{
	if(n <= m)
	{
		if(n == m)return 2;
		return 1;
	}
    vector<ll> mine(m,0);
    for(int i = 0; i < m-1; i++)mine[i] = 1;
    mine[m-1] = 2;
    matrix T(m,vector<ll>(m));
    for(int i = 0; i < m-1; i++)
    {
    	T[i][i+1] = 1;
    }
    T[m-1][m-1] = 1;
	T[m-1][0] = 1;
    matrix C = pow(T,n-1);
    ll res = 0;
    for(int i = 0; i < m; i++)
    {
        res = (res+C[0][i]*mine[i])%MOD;
    }
    return res;
}

int main()
{
	ll n;
	cin >> n >> m;
    cout << fib(n) << endl;
}

#include <bits/stdc++.h>
#define INF (1<<25)
#define MAXN 2000005
#define P int(1000000007)
using namespace std;
typedef long long ll;

ll N;
const int M = 100;

struct mat{
	ll a[M][M];
	mat(){
		memset(a, 0, sizeof(a));
	}

	mat operator * (const mat& n1) const{
		mat res;

		for(int i=0;i<M;i++){
			for(int j=0;j<M;j++){
				for(int k=0;k<M;k++){
					res.a[i][j] = (res.a[i][j] + a[i][k]*n1.a[k][j]%P) % P;
				}
			}
		}
		return res;
	}

	mat qpow(ll n){
		mat res,x;
		memcpy(x.a, a, sizeof(a));
		for(int i=0;i<M;i++) res.a[i][i] = 1;

		while(n){
			if(n&1) res = res * x;
			x = x * x;
			n /= 2;
		}
		return res;
	}

	void print(){
		cout<<"%%%%"<<endl;
		for(int i=0;i<M;i++){
			for(int j=0;j<M;j++) cout<<a[i][j]<<" ";
			cout<<endl;
		}
	}
};

int main(){

	int Q;
	cin>>N>>Q;

	mat A;
	for(int i=0;i<Q-1;i++) A.a[i+1][i] = 1;
	A.a[0][Q-1] = A.a[Q-1][Q-1] = 1;

	if(N<Q){
		cout<<"1"<<endl;
		return 0;
	}
	mat res = A.qpow(N-Q);

	ll ans = 0;
	for(int i=0;i<Q;i++){
		if(i<Q-1) ans = (ans + res.a[i][Q-1]) % P;
		else ans = (ans + 2*res.a[i][Q-1]% P) % P;
	}

	cout<<ans<<endl;

	return 0;
}

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;

#define fill(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define sz(x) (int)x.size()
#define F first
#define S second
#define FOR(i,a,b) for(int i = a; i<=b; ++i)
#define NFOR(i,a,b) for(int i = a; i>=b; --i)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
const ll INF = 1e18;
const ll mod = 1e9+7;
const int N = 1e5+10;

const int SZ=110;
int actualSize;

struct matrix
{
	ll arr[SZ][SZ];

	void makezeros()
	{
		for(int i=0;i<SZ;i++)
		for(int j=0;j<SZ;j++)
		arr[i][j]=0;
	}

	void base()
	{
		makezeros();
		arr[0][0] = 1;
		arr[0][actualSize-1] = 1;
		for(int i=1;i<actualSize;i++)
		arr[i][i-1] = 1;
	}

	void makeiden()
	{
		makezeros();
		for(int i=0;i<SZ;i++)
		{
			arr[i][i] = 1;
		}
	}

	ll answer(){
		ll ans = 0;
		for(int i=0;i<actualSize;i++)
		ans+=arr[0][i];

		ans%=mod;
		if(ans<0)
		ans+=mod;

		return ans;
	}

	matrix operator + (const matrix &o) const
	{
		matrix res;
		for(int i=0;i<SZ;i++)
		{
			for(int j=0;j<SZ;j++)
			{
				res.arr[i][j] = arr[i][j] + o.arr[i][j];
				if(res.arr[i][j]>=mod)
				res.arr[i][j]-=mod;
			}

		}
		return res;
	}

	matrix operator * (const matrix &o) const
	{
		matrix res;
		for(int i=0;i<actualSize;i++)
		{
			for(int j=0;j<actualSize;j++)
			{
				res.arr[i][j] = 0;
				for(int k=0;k<actualSize;k++)
				{
					res.arr[i][j]+=arr[i][k] * o.arr[k][j];
					res.arr[i][j]%=mod;
				}
			}
		}
		return res;
	}
};

matrix power(matrix a, ll b)
{
	matrix ret;
	ret.makeiden();

	if(b<=0)
	return ret;

	while(b)
	{
		if(b & 1)
		{
			ret = ret * a;
		}
		a = a * a;
		b >>= 1;
	}
	return ret;
}

int main(){
  fast;

  ll n;
  cin>>n>>actualSize;

  matrix mat;

  mat.base();
  mat = power(mat,n-actualSize+1);
  cout<<mat.answer()<<endl;

  return 0;
}

#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")
#pragma GCC optimize("section-anchors")
#pragma GCC optimize("profile-values,profile-reorder-functions,tracer")
#pragma GCC optimize("vpt")
#pragma GCC optimize("rename-registers")
#pragma GCC optimize("move-loop-invariants")
#pragma GCC optimize("unswitch-loops")
#pragma GCC optimize("function-sections")
#pragma GCC optimize("data-sections")
#pragma GCC optimize("branch-target-load-optimize")
#pragma GCC optimize("branch-target-load-optimize2")
#pragma GCC optimize("btr-bb-exclusive")
#include <iomanip>
#include <cstdio>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <ctime>
#include <random>
#include <queue>
#include <bitset>
#include <iostream>
#include <complex>
#include <stdio.h>
#include <chrono>
#include <math.h>
// #include <priority_queue>

// #include <bits/stdc++.h>

#pragma warning(disable : 4996)

using namespace std;

const int MAXN = 2e5 + 10;
const double EPS = 1e-7;
const long long p = 43;
const long long obrp = 510729669;
const unsigned long long INF = (1 << 30) - 1 + (1 << 30);
const int MOD = 1e9 + 7;
const long long half = (MOD + 1) / 2;
const double pi = acos(-1);

#ifdef _DEBUG
double mytime;
#endif

unordered_map<long long, long long> dp;
int kek = 0;
long long ONE = 1;

inline long long func(const long long &n, const long long &m) {
	if (n < m) return 1;
	if (dp.count(n)) return dp[n];
	//cout << n << "\n";
	kek++;
	long long ans = 0;
	//long long x = n / 2;
	ans = func(n >> 1, m) * func(n - (n >> 1), m);
	for (long long i = 1; i < m; i++) {
		if ((n >> 1) - i >= 0 && n - (n >> 1) - (m - i) >= 0) {
			ans += func((n >> 1) - i, m) * func(n - (n >> 1) - m + i, m);
		}
		if (((i >> 3) & 1) > 0) {
			ans %= MOD;
		}
	}
	ans %= MOD;
	// n / 2 .. n / 2 - m
	// n / 4 .. n / 4 - m / 2 - m
	// n / 8 .. n / 8 - m / 4 - m / 2 - m
	// sum x = 0 .. log n ( m * (2 - 1 / (2 ^ x)) )
	// m * log n * 2
	// m * (log n + (log n - 1) / 2 + (log n - 2) / 4 + (log n - 3) / 8)
	dp[n] = ans;
	return ans;
}

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	mytime = clock();
	srand(time(0));
#endif
#ifndef _DEBUG
	/*freopen("caves.in", "r", stdin);
	freopen("caves.out", "w", stdout);*/
#endif

	//srand(time(0));
	//srand(322);
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	// CODE

	long long n;
	int m;
	cin >> n >> m;
	cout << (func(n, m)) << "\n";
	//cout << kek << "\n";

	// CODE

#ifdef _DEBUG
	mytime = clock() - mytime;
	cout << "\n\n" << fixed << setprecision(15) << mytime / CLOCKS_PER_SEC * 1000 << "\n";
	//printf("\n\n%llf ms", mytime / CLOCKS_PER_SEC * 1000);
	//system("pause");
#endif
	return 0;
}

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;

#define fill(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define sz(x) (int)x.size()
#define F first
#define S second
#define FOR(i,a,b) for(int i = a; i<=b; ++i)
#define NFOR(i,a,b) for(int i = a; i>=b; --i)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
const ll INF = 1e18;
const ll mod = 1e9+7;
const ll mod2 = mod*mod;
const int N = 1e5+10;

const int SZ=110;
int actualSize;

ll res[SZ][SZ];
struct matrix
{
	ll arr[SZ][SZ];

	void makezeros()
	{
		for(int i=0;i<actualSize;i++)
		for(int j=0;j<actualSize;j++)
		arr[i][j]=0;
	}

	void base()
	{
		makezeros();
		arr[0][0] = 1;
		arr[0][actualSize-1] = 1;
		for(int i=1;i<actualSize;i++)
		arr[i][i-1] = 1;
	}

	void makeiden()
	{
		makezeros();
		for(int i=0;i<actualSize;i++)
		{
			arr[i][i] = 1;
		}
	}

	ll answer(){
		ll ans = 0;
		for(int i=0;i<actualSize;i++)
		ans+=arr[0][i];

		ans%=mod;
		if(ans<0)
		ans+=mod;

		return ans;
	}

	void add(const matrix &o)
	{
		for(int i=0;i<actualSize;i++)
		{
			for(int j=0;j<actualSize;j++)
			{
				arr[i][j] = arr[i][j] + o.arr[i][j];
				if(arr[i][j]>=mod)
				arr[i][j]-=mod;
			}
		}
	}

	void mult(const matrix &o)
	{
		for(int i=0;i<actualSize;i++)
		for(int j=0;j<actualSize;j++)
		res[i][j]=0;

		for(int i=0;i<actualSize;i++)
		{
			for(int k=0;k<actualSize;k++)
			{
				for(int j=0;j<actualSize;j++)
				{
					res[i][j] += arr[i][k]*o.arr[k][j];
					if(res[i][j]>=mod2)
					res[i][j]-=mod2;
				}
			}
		}

		for(int i=0;i<actualSize;i++)
		for(int j=0;j<actualSize;j++)
		arr[i][j]=res[i][j]%mod;
	}

};

matrix power(matrix& a, ll b)
{
	matrix ret;
	ret.makeiden();

	if(b<=0)
	return ret;

	while(b)
	{
		if(b & 1)
		{
			ret.mult(a);
		}
		a.mult(a);
		b >>= 1;
	}
	return ret;
}

int main(){
  fast;

  ll n;
  cin>>n>>actualSize;

  matrix mat;

  mat.base();
  mat = power(mat,n-actualSize+1);
  cout<<mat.answer()<<endl;

  return 0;
}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define F first
#define S second
#define ld long douroote
#define pb push_back
#define sz size
#define ll long long
#define ull unsigned long long
#define INF 0x7f7f7f7f
#define sc(a) scanf("%d",&a)
#define scll(a) scanf("%lld",&a)
#define scc(a) scanf(" %c",&a)
#define scs(a) scanf(" %s",a)
#define me(a,b) memset(a,b,sizeof a)
#define all(a) a.begin(),a.end()
#define allr(a,n) a,a+n
#define loop(a,s,e) for(ll a=s;a<=e;a++)
#define read_arr(a,s,n) for(int i=s;i<n+s;i++){sc(a[i]);}
#define read_arr_ll(a,s,n) for(int i=s;i<n+s;i++){scll(a[i]);}
#define err(a,s) cerr<<a<<s;
#define err_arr(a,s,n) for(int i=s;i<n+s;i++){cerr<<a[i]<<" ";}cerr<<endl;
#define prtll(x) printf("%lld",x);
#define prt(x) printf("%d",x);
using namespace __gnu_pbds;
using namespace std;
const int sz=100;
ll mod=1e9+7,n,m,t;
struct matrix {
  int data[sz][sz];
  int row,col;
  matrix(ll val=0) {
    col=sz;
    row=sz;
    for (int i=0;i<row;i++){
      for (int j=0;j<col;j++){data[i][j]=0;}
      data[i][i] = val;
    }
  }

  matrix operator * (const matrix &other) {
    matrix ret;
    for (int i=0; i<row; i++) {
      for (int j=0; j<other.col;j++) {
        for (int k=0; k<col;k++) {
          ret.data[i][j]=(1LL * data[i][k]*other.data[k][j]+ret.data[i][j])%mod;
          ret.data[i][j]%=mod;
        }
      }
    }

    return ret;
  }
  void print(){
       printf("\n");
       for(int i = 0;i<row;++i){
        for(int j = 0;j<col;++j){printf("%lld ",data[i][j]);}
        printf("\n");
        }
        printf("\n");
   }
  matrix pow_(ll y) {
     matrix ret(1);
     matrix A=*this;
     for (; y; y >>= 1) {
      if (y & 1) ret = ret * A;
      A = A * A;
    }

    return ret;
  }
};

int main() {
  scll(n);scll(m);
  matrix a,b;
  for(int i=0;i<m;i++){a.data[0][i]=1;}
  for(int i=0;i<m-1;i++){b.data[i+1][i]=1;}
   b.data[m-1][m-1]=1;
   b.data[0][m-1]+=1;

   b=b.pow_(n);
   a=a*b;
  printf("%d\n",a.data[0][0]);

  return 0;
}

/**
dp(i)=dp(i-1)+dp(i-m);

a=|11111|
b=|000|
  |101|
  |011|
**/

#include<iostream>
#include<cstring>
using namespace std;
#define ll long long
const int maxn=105;
ll mod = 1e9+7;
ll n;
int m;
struct Matrix
{
    ll Mat[maxn][maxn];
    Matrix() { memset(Mat,0,sizeof(Mat)); }
};

Matrix Mat_mul(Matrix a,Matrix b)
{
    Matrix temp;
    for(int i=0;i<m;++i){
        for(int j=0;j<m;++j){
            for(int k=0;k<m;++k){
                temp.Mat[i][j]+=a.Mat[i][k]*b.Mat[k][j];
                temp.Mat[i][j]%=mod;
            }
        }
    }
    return temp;
}

Matrix m_fpow(Matrix a,ll n)
{
    Matrix ans;
    for(int i=0;i<m;i++) ans.Mat[i][i]=1;
    while(n!=0){
        if(n&1) ans=Mat_mul(ans,a);
        n>>=1;
        a=Mat_mul(a,a);
    }
    return ans;
}
int main(){
    cin>>n>>m;
    if(n<m) cout<<"1\n";
    else{
        Matrix a,b,ans;
        a.Mat[0][0]=a.Mat[0][m-1]=1;
        for(int i=1;i<m;i++) a.Mat[i][i-1]=1;
        for(int i=0;i<m;i++) b.Mat[i][0]=1;
        ans=Mat_mul(m_fpow(a,1ll*(n-m+1)),b);
        cout<<ans.Mat[0][0]<<endl;
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9+7;

vector<vector<int>> mult(vector<vector<int>>& a, vector<vector<int>>& b) {
    if(a.size() == 0) return {};
    if(a[0].size() == 0) return {};
    if(b.size() == 0) return {};
    if(b[0].size() == 0) return {};
    if(a[0].size() != b.size()) return {};
    int resultRow = a.size(), resultCol = b[0].size(), n = a[0].size();
    vector<vector<int> > product(resultRow, vector<int>(resultCol));
    for(int i = 0; i < resultRow; ++i) {
        for(int j = 0; j < resultCol; ++j) {
            product[i][j] = 0;
            for(int k = 0; k < n; ++k) {
                ll temp = (ll)a[i][k] * b[k][j];
                temp %= mod;
                product[i][j] += temp;
                product[i][j] %= mod;
            }
        }
    }
    return product;
}

vector<vector<int>> power(vector<vector<int>>& matrix, ll b) {
    if (b <= 1) return matrix;
    vector<vector<int>> temp = power(matrix, b/2);
    if (b % 2 == 0) return mult(temp, temp);
    vector<vector<int>> v = mult(temp,temp);
    return mult(v, matrix);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    long long n, m;
    cin >> n >> m;

    if(n < m) {
        cout << 1 << endl;
        return 0;
    }

    vector<vector<int>> v(m,vector<int>(m,0));
    v[0][0] = 1;
    v[0][m-1] = 1;
    for(int i = 1; i < m; i++) {
        v[i][i-1] = 1;
    }

    v = power(v,n);

    cout << v[0][0] << endl;

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
ll n,m;
struct mat
{
    ll a[105][105];
};
mat mat_mul(mat x,mat y)
{
    mat res;
    memset(res.a,0,sizeof(res.a));
    for(int i=0;i<m;i++)
        for(int j=0;j<m;j++)
        for(int k=0;k<m;k++)
        res.a[i][j]=(res.a[i][j]+x.a[i][k]*y.a[k][j])%MOD;
    return res;
}
void mat_pow(ll n)
{
    mat c,res;
    c.a[0][0]=c.a[0][m-1]=1;
    for(int i=1;i<m;i++)
    {
        c.a[i][i-1]=1;
    }

    memset(res.a,0,sizeof(res.a));
    for(int i=0;i<m;i++) res.a[i][i]=1;
    n--;
    while(n)
    {
        if(n&1) res=mat_mul(res,c);
        c=mat_mul(c,c);
        n=n>>1;
    }
    c=res;
    ll ans=c.a[m-1][0]*2%MOD;
    for(int j=1;j<m;j++)ans=(ans+c.a[m-1][j])%MOD;
    cout<<ans<<endl;
}
int main()
{
    cin>>n>>m;
        mat_pow(n);
    return 0;
}

#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
unordered_map<ll,ll>dp;
ll n,m;
ll solve(ll n)
{
    if(n<0)
        return 0;
    if(n<m)
        return 1;
    //because if n<m no magic gem can be split
    if(dp.find(n)!=dp.end())
        return dp[n];
    //because if already computed dont do the the computation i.e.memoisation
    ll mid=((n+1)/2),result=((solve(mid-1)%mod)*(solve(n-mid)%mod))%mod;
    for(int i=1;i<=m;i++)
    {
        result=(result+(solve(mid-i)%mod)*(solve(n-mid-(m-i))%mod))%mod;
    }
    dp[n]=result;
    return dp[n];
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cin>>n>>m;
    dp[0]=0;
    dp[1]=1;
    cout<<solve(n);
    return 0;
}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(c)	c.begin(), c.end()
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define trace(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {cout << "\n";}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {cerr << *it << " : " << a << " | "; err(++it, args...);}

typedef long long int lli;
typedef long double ld;
typedef pair<lli, lli> plli;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pair<lli, lli> > vplli;
typedef vector<lli> vlli;
typedef vector<vlli> vvlli;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef tree <lli, null_type, less<lli>, rb_tree_tag, tree_order_statistics_node_update >ordered_set;

#define PI 3.141592653589793
#define mod (lli)(1000*1000*1000+7)
#define mod2 1000000014000000049L

template<typename T> T gcd(T a, T b) { if (a == 0) return b; return gcd(b % a, a); }
template<typename T> T pow(T a, T b, lli m) {T ans = 1; while (b > 0) { if (b % 2 == 1) ans = ((ans % m) * (a % m)) % m; b /= 2; a = ((a % m) * (a % m)) % m; } return ans % m; }
const int N = 100010;

void add(lli& a, lli b) {
	a = (a % mod + b % mod) % mod;
}

lli sub(lli a, lli b) {
	a -= b;
	if (a < 0)	a += mod;
	return a;
}

lli mult(lli a, lli b) {
	return (((a % mod) * (b % mod)) % mod);
}

lli power(lli a, lli b) {
	lli v = pow(a, b, mod);
	return v;
}

void print(vvlli& arr) {
	for (int i = 0; i < arr.size(); i++) {
		for (int j = 0; j < arr.size(); j++) {
			cout << arr[i][j] << " \n"[j == arr.size() - 1];
		}
	}
}

void mult(vvlli& a, vvlli& b) {
	vvlli c(a.size(), vlli(b[0].size(), 0ll));
	for (int r = 0; r < a.size(); ++r) {
		for (int x = 0; x < b.size(); ++x) {
			for (int j = 0; j < b[0].size(); ++j) {
				c[r][j] += a[r][x] * b[x][j];
				if ( c[r][j] >= mod2 )
					c[r][j] -= mod2;
			}
		}
	}
	for (int i = 0; i < c.size(); i++) {
		for (int j = 0; j < c[i].size(); j++) {
			a[i][j] = c[i][j] % mod;

		}
	}
}

void pow(vvlli& arr, lli n) {
	if (n <= 1) return;

	if (n & 1) {
		vvlli temp = arr;
		pow(arr, n / 2ll);
		mult(arr, arr);
		mult(arr, temp);
	} else {
		pow(arr, n / 2ll);
		mult(arr, arr);
	}
}

int main() {
	fio;
	lli n, m;
	cin >> n >> m;
	if (n - m < 0) {
		// 1 1 1 1 1 1 1 1...
		cout << "1\n";
		return 0;
	}

	vvlli cof(m, vlli(m, 0ll));
	cof[0][0] = 1;
	cof[0][m - 1] = 1;
	for (int i = 1; i < cof.size(); i++) {
		cof[i][i - 1] = 1;
	}

	pow(cof, n - m + 1);
	lli ans = 0ll;
	for (int i = 0; i < m; i++) {
		ans = ans + cof[0][i];
		ans %= mod;
	}
	cout << ans << "\n";
}

#include <algorithm>
#include <climits>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

#ifndef TEST
#define endl '\n'
#endif
#define eps 1e-9

#define ZERO(a) memset(a, 0, sizeof(a))

typedef long long int ll;

const ll MOD = 1000 * 1000 * 1000 + 7;
const int MAT_SIZE = 105;

template <typename T>
T add(T a, T b) {
  return (a + b) % MOD;
}
template <typename T>
T mul(T a, T b) {
  return (a * b) % MOD;
}

template <typename T>
class Matrix {
 public:
  T data[MAT_SIZE][MAT_SIZE];
  int n, m;

  Matrix(int a, int b);
  Matrix(const Matrix<T> &A);
  Matrix<T> operator*(const Matrix<T> &)const;
  Matrix<T> operator^(long long int) const;
};

template <typename T>
Matrix<T>::Matrix(int a, int b) {
  if (a > MAT_SIZE || b > MAT_SIZE) {
    cerr << "Oversized matrix" << endl;
    exit(1);
  }
  n = a;
  m = b;
  ZERO(data);
}

template <typename T>
Matrix<T>::Matrix(const Matrix<T> &A) {
  n = A.n;
  m = A.m;
  memcpy(data, A.data, sizeof(A.data));
}

template <typename T>
Matrix<T> Matrix<T>::operator*(const Matrix<T> &b) const {
  Matrix<T> c(this->n, b.m);
  if (this->m != b.n) {
    cerr << "non compatible matrix multiplication\n";
    return c;
  }
  for (int i = 0; i < c.n; i++) {
    for (int j = 0; j < c.m; j++) {
      for (int k = 0; k < this->m; k++) {
        c.data[i][j] = add(c.data[i][j], mul(this->data[i][k], b.data[k][j]));
      }
    }
  }
  return c;
}

template <typename T>
Matrix<T> Matrix<T>::operator^(long long int pow) const {
  if (this->n != this->m) {
    cout << "can't square non-square matrix\n";
    Matrix<T> a(1, 1);
    return a;
  }
  // Identity matrix initially
  Matrix<T> ret(this->n, this->n);
  for (int i = 0; i < this->n; i++) {
    for (int j = 0; j < this->n; j++) {
      if (i == j) ret.data[i][j] = 1;
    }
  }

  // The even power of the matrix
  Matrix<T> a = (*this);

  while (pow > 0) {
    if (pow & 1) ret = ret * a;

    pow >>= 1;
    a = a * a;
  }
  return ret;
}

int main() {
#ifndef TEST
  ios_base::sync_with_stdio(false);
  cin.tie(0);
#endif
  ll n, m;
  cin >> n >> m;
  Matrix<ll> A(1, m);
  Matrix<ll> M(m, m);
  for (int i = 0; i < m; i++) {
    A.data[0][i] = 1;
  }
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < m; j++) {
      M.data[j][i] = 0;
      if (j == i + 1) {
        M.data[j][i] = 1;
      }
    }
  }
  M.data[0][m - 1] = M.data[m - 1][m - 1] = 1;
  ll ret = (A * (M ^ n)).data[0][0];
  cout << ret << endl;
}

#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <climits>
#include <functional>
#include <unordered_set>
#include <unordered_map>
#include <cassert>
#include <bitset>

using namespace std;

typedef long long LL;
typedef long double LD;
typedef vector<int> ROW;
typedef vector<ROW> MATR;

const int M = int(1e9) + 7;

MATR mult(MATR& m1, MATR& m2) {
	assert(m1.size() == m2.size());
	int n = m1.size();
	MATR prod(n, ROW(n));
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			for (int k = 0; k < n; ++k) {
				prod[i][j] = (prod[i][j] + (LL)m1[i][k] * m2[k][j]) % M;
			}
		}
	}
	return move(prod);
}

int main() {
	LL n, m;
	scanf("%lld %lld", &n, &m);
	MATR t(m, ROW(m)), tpow;
	t[0][0] = 1, t[0][m - 1] = 1;
	for (int i = 1; i < m; ++i) {
		t[i][i - 1] = 1;
	}
	tpow = t;
	MATR ans(m, ROW(m));
	for (int i = 0; i < m; ++i) {
		ans[i][i] = 1;
	}
	for (int b = 0; b < 61; ++b) {
		if (((n >> b) & 1LL) == 1) {
			ans = mult(ans, tpow);
		}
		tpow = mult(tpow, tpow);
	}
	printf("%d", ans[0][0]);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define rep(i, a, b) for (int i = a; i < b; i++)
#define na0(x) memset(x, 0, sizeof x)
#define na1(x) memset(x, -1, sizeof x)
#define yes cout << "Yes" << endl
#define no cout << "No" << endl

deque <int> divisors;
vector <int> primes, factors;

const ll mod = 1e9 + 7;
ll off;

void find_off(int x)
{
    off = 1;
    while (off < x) off *= 2;
    return;
}

void find_divisors(int x)
{
    //sqrt(x)
    divisors.clear();
    bool flag = 0;

    if ((int)sqrt(x) * (int)sqrt(x) == x)
    {
        flag = 1;
        divisors.push_back(sqrt(x));
    }
    for (int i = sqrt(x)-flag; i > 0; i--)
    {
        if (x % i == 0)
        {
            divisors.push_front(i);
            divisors.push_back(x/i);
        }
    }
    return;
}

void find_primes(ll x)
{
    //sqrt(x) * log log x
    bool prime[x+1];
    memset(prime, true, sizeof(prime));

    for (int p = 2; p * p <= x; p++)
    {
        if (prime[p] == true)
        {
            for (int i = p*p; i <= x; i += p)
                prime[i] = false;
        }
    }

    for (int i = 2; i <= x; i++)
    {
        if (prime[i]) primes.push_back(i);
    }

    sort(primes.begin(), primes.end());

    return;
}

bool is_prime(ll x)
{
    //sqrt(x)
    if (x == 2) return 1;
    for (int i = 2; i <= sqrt(x); i++)
    {
        if (x%i == 0) return 0;
    }
    return 1;
}

void find_factors(ll x)
{
    //sqrt(x)
    factors.clear();
    while (x%2 == 0)
    {
        factors.push_back(2);
        x = x/2;
    }

    for (int i = 3; i <= sqrt(x); i = i+2)
    {
        while (x%i == 0)
        {
            factors.push_back(i);
            x = x/i;
        }
    }

    if (x > 2)
        factors.push_back(x);

    sort(factors.begin(), factors.end());

    return;
}

bool is_palindrome(string x)
{
    // O(len(x))
    bool qw = 1;
    for (int i = 0; i < x.size() / 2; i++)
    {
        if (x[i] != x[x.size() - 1 - i]) qw = 0;
    }
    return qw;
}

ll gcd(ll x, ll y)
{
    //O(1)
    if (y == 0)
        return x;
    return gcd(y, x % y);
}

ll lcm(ll x, ll y)
{
    //O(1)
    return (x*y)/(gcd(x,y));
}

ll add(ll x, ll y)
{
    return (x+y+mod)%mod;
}

ll mul(ll x, ll y)
{
    return (x*y+mod)%mod;
}

ll pot(ll x, ll y)
{
    if (y == 0) return 1;
    if (y == 1) return x;

    if (y % 2 == 0)
    {
        ll z = pot(x, y / 2);
        return mul(z, z);
    }
    else
    {
        ll z = pot(x, y / 2);
        return mul(mul(z, z), x);
    }
}

ll N, M;
ll dp[111];
ll mat[111][111][62], curr[111][111], curr1[111][111];
ll pot2[62];

void mat_pot(ll x)
{
    bool flag = 0;
    rep(i, 0, 61)
    {
        if ((pot2[i] & x) != 0)
        {
            if (!flag)
            {
                flag = 1;
                rep(j, 1, M + 1)
                {
                    rep(k, 1, M + 1)
                    {
                        curr[j][k] = mat[j][k][i];
                    }
                }
            }
            else
            {
                rep(k, 1, M + 1)
                {
                    rep(j, 1, M + 1)
                    {
                        curr1[k][j] = 0;
                        rep(l, 1, M + 1)
                        {
                            curr1[k][j] = add(curr1[k][j], mul(curr[k][l], mat[l][j][i]));
                        }
                    }
                }
                rep(j, 1, M + 1)
                {
                    rep(k, 1, M + 1)
                    {
                        curr[j][k] = curr1[j][k];
                    }
                }
            }
        }
    }

    return;
}

void solve(ll x)
{
    mat_pot(x);
    ll sol = 0;

    rep(i, 1, M)
    {
        sol = add(sol, curr[M][i]);
    }

    sol = add(sol, mul(curr[M][M], 2));

    cout << sol;

    return;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin >> N >> M;

    if (M > N)
    {
        cout << 1;
        return 0;
    }
    if (M == N)
    {
        cout << 2;
        return 0;
    }

    pot2[0] = 1;
    rep(i, 1, 61) pot2[i] = pot2[i - 1] * 2;

    rep(i, 1, M)
    {
        mat[i][i + 1][0] = 1;
    }
    mat[M][1][0] = 1;
    mat[M][M][0] = 1;

    rep(i, 1, 61)
    {
        rep(j, 1, M + 1)
        {
            rep(k, 1, M + 1)
            {
                rep(l, 1, M + 1)
                {
                    mat[j][k][i] = add(mat[j][k][i], mul(mat[j][l][i - 1], mat[l][k][i - 1]));
                }
            }
        }
    }

    solve(N - M);
    return 0;
}

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>
#include <cmath>
#include <functional>
#include <algorithm>
#include <utility>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iterator>
#include <fstream>
#include <iomanip>
#include <time.h>
#include <complex>
//#pragma comment(linker, "/STACK:16777216")

using namespace std;

typedef long double C;
typedef complex<C> P;

#define X real()
#define Y imag()
#define Size(X) (int)X.size()
#define int long long
//#define double float
#define ui unsigned int
#define mp make_pair
#define timer fghge
#define y1 yjyjyju
#define all(X) (X).begin(), (X).end()
#define endl '\n'

int n, m;

vector<int> a;
vector<vector<int>> b;
const int mod = 1e9 + 7;

void operator*= (vector<vector<int>>& a, vector<vector<int>>& b) {
	vector<vector<int>> res(a.size(), vector<int>(b[0].size()));
	for (int i = 0; i < a.size(); i++)
		for (int j = 0; j < b[0].size(); j++)
			for (int q = 0; q < a[0].size(); q++)
				res[i][j] = (res[i][j] + (a[i][q] * b[q][j]) % mod) % mod;
	a = res;
}

void binpow(int n) {
	vector<vector<int>> res(m + 1, vector<int>(m + 1));
	for (int i = 0; i <= m; i++)
		res[i][i] = 1;
	while (n) {
		if (n & 1) {
			res *= b;
			n--;
		}
		else {
			b *= b;
			n >>= 1;
		}
	}
	b = res;
}

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	cin >> n >> m;

	a.assign(m + 1, 1);
	b.assign(m + 1, vector<int>(m + 1));
	a[m] = 2;

	for (int i = 0; i < m; i++)
		b[i + 1][i] = 1;
	b[1][m] = 1;
	b[m][m] = 1;

	if (n > m) {
		binpow(n - m);
		vector<int> ans(m + 1);
		for (int j = 0; j <= m; j++)
			for (int q = 0; q <= m; q++)
				ans[j] = (ans[j] + (a[q] * b[q][j]) % mod) % mod;

		cout << ans.back();
	}
	else
		cout << a[n];
	return 0;
}

///-------------------///
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>

///   --Constants--  ///
#define MOD 1000000007
#define INF 2000000000
#define INFLL 9000000000000000000ll

///  --  --  ///
#define fi first
#define se second
#define pb push_back
//#define mp make_pair
#define elif else if
#define sz(a) ((long long)((a).size()))
#define all(a) (a).begin() , (a).end()

#define fastio ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define what(x)  cout << #x << " is " << x << '\n'

#define int long long
#define left aertuidfghjkcvbn
#define right tyuikjhgvbnm

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector< vector<ll>> vvi;

const int MAXN = 300010, MAXM = 200, MAXP=100;

ll n, m;

vvi mult(vvi a, vvi b, int n)
{
    vvi rez(m, vector<ll>(m));
    for(int i = 0; i<n; i++)
        for(int j = 0; j<n; j++)
            for(int k = 0; k<n; k++)
            rez[i][j]=(rez[i][j]+a[i][k]*b[k][j])%MOD;
    return rez;
}
vvi ppow(vvi a, ll n)
{
    vvi rez(m, vector<ll>(m));
    for(int i = 0; i<m; i++)
        rez[i][i]=1;
    while(n)
    {
        if(n&1)
        {
        rez = mult(rez, a, m);
        }
        n>>=1;
            a=mult(a, a, m);
    }
    return rez;
}

int32_t main()
{

    fastio;
//    ifstream cin("file.in");
//    ofstream cout("file.out");

//    cin >> s;
    cin >> n >> m;
    vvi a(m, vector<ll>(m));
    for(int i = 0; i<m-1; i++)
    {
        a[i+1][i]=1;
    }
    a[m-1][m-1]=1;
    a[0][m-1]=1;

    a = ppow(a, n);
    cout << a[m-1][m-1] << '\n';

    //1 1 2 3 5 8 13

}

#include <bits/stdc++.h>
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define popcnt(x) __builtin_popcount(x)
#define inf 0x3f3f3f3f
#define watch(x) cout << (#x) << " is " << (x) << endl
#define rand() (rand() << 15 | rand())
#define Matrix vector<vector<long long>>
using namespace std;
const int MOD = 1e9 + 7;

Matrix matrixMul(Matrix &a , Matrix &b){
    int p = a.size() , q = a[0].size() , r = b.size();
    Matrix ret(p , vector<long long>(r , 0));
    for(int i = 0 ; i < p ; ++i){
        for(int j = 0 ; j < r ; ++j){
            for(int k = 0 ; k < q ; ++k){
                ret[i][j] += (a[i][k] * b[k][j]) % MOD;
                ret[i][j] %= MOD;
            }
        }
    }
    return ret;
}

Matrix matrixPow(Matrix base , long long n){
    Matrix ret(base.size() , vector<long long>(base.size()));
    for(int i = 0 ; i < (int)base.size() ; ++i)
        ret[i][i] = 1;
    while(n){
        if(n & 1)ret = matrixMul(ret , base);
        base = matrixMul(base , base);
        n >>= 1;
    }
    return ret;
}

int main(){
#ifndef ONLINE_JUDGE
    freopen("input.txt" , "r" , stdin);
#endif
    ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
    long long n;
    int m;
    cin >> n >> m;
    if(n < m){
        cout << 1 << endl;
        return 0;
    }
    Matrix mat1(m , vector<long long>(1 , 1));
    Matrix mat2(m , vector<long long>(m , 0));
    mat2[0][0] = mat2[0][m - 1] = 1;
    for(int i = 1 ; i < m ; ++i)
        mat2[i][i - 1] = 1;

    Matrix nth = matrixPow(mat2 , n - m + 1);
    Matrix res = matrixMul(nth , mat1);
    cout << res[0][0] << endl;
}

// arock - 2019-02-23

#include <iostream>
#include <vector>

using i64 = long long;
using u64 = unsigned long long;

template <class S> struct promote {typedef S T;};
template<> struct promote<int> {typedef i64 T;};
template <class T> using up = typename promote<T>::T;

template <class T> struct matrix : std::vector<std::vector<T>> {
	size_t N, M;
	matrix(size_t n, size_t m, T init = {}) :
	std::vector<std::vector<T>>(n, std::vector<T>(m, init)), N(n), M(m) {}

	matrix operator*(const matrix& other) const {
		matrix res(N, other.M);
		for (size_t i = 0; i < res.N; i++) {
			for (size_t j = 0; j < res.M; j++) {
				for (size_t k = 0; k < M; k++) {
					res[i][j] += (*this)[i][k] * other[k][j];
				}
			}
		}
		return res;
	}

	matrix operator^(u64 p) {
		if (p == 0) {
			return identity(N);
		} else if (p & 1) {
			return (*this^(p-1)) * (*this);
		} else {
			auto half = *this^(p>>1);
			return half * half;
		}
	}

	static matrix identity(size_t n) {
		matrix I(n, n);
		for (size_t i = 0; i < n; i++) {
			I[i][i] = 1;
		}
		return I;
	}
};

template <class T, T MOD> struct Z {
	T val;
	Z(T v = {}) : val(v) {}

	void operator+=(const Z& other) {
		if ((val += other.val) >= MOD) {
			val -= MOD;
		}
	}

	Z operator*(const Z& other) const {
		return T(up<T>(val) * other.val % MOD);
	}

	friend std::ostream& operator<<(std::ostream& out, const Z& z) {
		return out << z.val;
	}
};

int main() {
	std::ios::sync_with_stdio(0), std::cin.tie(0), std::cout.tie(0);

	i64 N;
	int M;
	std::cin >> N >> M;

	matrix<Z<int, 1000000007>> F0(M, 1, 1), FF(M, M);
	for (int i = 0; i + 1 < M; i++) {
		FF[i][i + 1] = 1;
	}
	FF[M - 1][0] = FF[M - 1][M - 1] = 1;

	std::cout << ((FF^N) * F0)[0][0] << '\n';
}

#include<bits/stdc++.h>
using namespace std;

typedef long long int ll;
#define MOD 1000000007
unordered_map<ll,ll> mem;
ll m;
ll DP(ll n){
	if(n<0)return 0;
	if(n<m)return 1;
	if(mem.find(n)!=mem.end())return mem[n];
	ll  mid = (n+1)/2, ret = (DP(mid-1)*DP(n-mid))%MOD;
	for(ll i = 1; i<=m;i++){

		ret = (ret+(DP(mid-i)*DP(n-m-mid+i))%MOD)%MOD;
	}
	return mem[n]=ret;
}

int main(){
	ll n;
	cin>>n>>m;
	mem[0]=0;
	mem[1]=1;
	cout<<DP(n);
	return 0;
}

#include "bits/stdc++.h"

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back
#pragma GCC optimize ("-O3")

using namespace std;

#define DEBUG_IS_VALID

#ifdef DEBUG_IS_VALID
#define DEB 1
#else
#define DEB 0
#endif
#define DUMPOUT cout
#define dump(...) if(DEB) DUMPOUT<<"  "<<#__VA_ARGS__<<" :["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl<<"    "; if(DEB) dump_func(__VA_ARGS__)
template<typename T1,typename T2>ostream& operator << (ostream& os, pair<T1,T2> p){cout << "(" << p.first << ", " << p.second << ")"; return os;}
template<typename T>ostream& operator << (ostream& os, vector<T>& vec) { os << "{"; for (int i = 0; i<vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : ", "); os << "}"; return os; }
template<typename T>ostream& operator << (ostream& os, set<T>& st){cout << "{"; for(auto itr = st.begin(); itr != st.end(); itr++) cout << *itr << (next(itr)!=st.end() ? ", " : ""); cout << "}"; return os;}
template<typename T1,typename T2>ostream& operator << (ostream& os, map<T1,T2> mp){cout << "{"; for(auto itr = mp.begin(); itr != mp.end(); itr++) cout << "(" << (itr->first) << ", " << (itr->second) << ")" << (next(itr)!=mp.end() ? "," : ""); cout << "}"; return os; }

void dump_func(){DUMPOUT << endl;}
template <class Head, class... Tail>void dump_func(Head&& head, Tail&&... tail){ DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...);}
template<class T> inline bool chmax(T& a,T const& b){if(a>=b) return false; a=b; return true;}
template<class T> inline bool chmin(T& a,T const& b){if(a<=b) return false; a=b; return true;}
void _main();
int main(){ cin.tie(0); ios::sync_with_stdio(false); _main(); return 0;}

using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

const int mod=1e9+7,INF=1<<29;
const double EPS=1e-5,PI=3.1415926535897932384626;
const ll lmod = 1e9+7,LINF=1LL<<59;

template<int MOD> struct ModInt {
    static const int Mod = MOD; unsigned x; ModInt() : x(0) { }
    ModInt(signed sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    ModInt(signed long long sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    int get() const { return (int)x; }
    ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; }
    ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }
    ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
    ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
    ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
    ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }
    ModInt inverse() const { long long a = x, b = MOD, u = 1, v = 0;
        while (b) { long long t = a / b; a -= t * b; std::swap(a, b); u -= t * v; std::swap(u, v); }
        return ModInt(u); }
    bool operator==(ModInt that) const { return x == that.x; }
    bool operator!=(ModInt that) const { return x != that.x; }
    ModInt operator-() const { ModInt t; t.x = x == 0 ? 0 : Mod - x; return t; }
};
template<int MOD> ostream& operator<<(ostream& st, const ModInt<MOD> a) { st << a.get(); return st; };
template<int MOD> ModInt<MOD> operator^(ModInt<MOD> a, unsigned long long k) {
    ModInt<MOD> r = 1; while (k) { if (k & 1) r *= a; a *= a; k >>= 1; } return r; }
template<typename T, int FAC_MAX> struct Comb { vector<T> fac, ifac;
    Comb(){fac.resize(FAC_MAX,1);ifac.resize(FAC_MAX,1); for(int i = 1; i < FAC_MAX; i++)fac[i]=fac[i-1]*i;
        ifac[FAC_MAX-1]=T(1)/fac[FAC_MAX-1];for(int i = FAC_MAX-2; i >= 1; i--)ifac[i]=ifac[i+1]*T(i+1);}
    T aPb(int a, int b) { if (b < 0 || a < b) return T(0); return fac[a] * ifac[a - b]; }
    T aCb(int a, int b) { if (b < 0 || a < b) return T(0); return fac[a] * ifac[a - b] * ifac[b]; }
    T nHk(int n, int k) { if (n == 0 && k == 0) return T(1); if (n <= 0 || k < 0) return 0;
        return aCb(n + k - 1, k); }}; // nHk = (n+k-1)Ck : n is separator

using mint =  ModInt<int(1e9+7)>;
using vm = vector<mint>;

template<class T>
struct Kitamasa {
  public:
	//漸化式 an = zenka[0] * an-k+1 + zenka[1] * an-k+2 + zenka[2] * an-k+3 + ......zenka[k-1]*an-1
	Kitamasa(const vector<T>&zenka) :z_size(zenka.size()), terms(2 * z_size - 1, vector<T>(z_size)) {
		for (int i = 0; i < z_size; ++i) {
			vector<T>a(z_size, static_cast<T>(0));
			a[i] = static_cast<T>(1);
			terms[i] = (a);
		}
		if (all_of(zenka.begin(), zenka.end(), [](const T&t) {return t == static_cast<T>(1); })) {
			//(N^2)
			vector<T>plus(z_size, 1);
			for (int i = z_size; i < 2 * z_size - 1; ++i) {
				if (i != z_size) {
					for (int j = 0; j <z_size; ++j) {
						plus[j] += plus[j];
					}
					plus[i - z_size - 1] -= 1;
				}
				terms[i] = (plus);
			}

		}
		else {
			//(N^3)
			for (int i = z_size; i < 2 * z_size - 1; ++i) {
				for (int j = 0; j < z_size; ++j) {
					for (int k = 0; k < z_size; ++k) {
						terms[i][j] += zenka[k] * terms[i - z_size + k][j];
					}
				}
			}
		}
	}

	//第num項を求める
	//
	//
	//引数
	//fst_terms 初項
	//fst_terms={a0,a1,a2,.......ak-1}
	//num:求める項数
	T solve(const vector<T>&fst_terms, const long long int num) {
		assert(fst_terms.size() == z_size);
		vector<T>v(getterm(num));
		T ans(0);
		for (int i = 0; i < z_size; ++i) {
			ans += fst_terms[i] * v[i];
		}
		return ans;
	}

private:

	vector<T>getterm(const long long int num) {
		if (num < static_cast<long long int >(z_size * 2 - 1)) {
			return terms[static_cast<int >(num)];
		}
		if (num % 2) {
			return plusone(multitwo(getterm(num / 2)));
		}
		else {
			return multitwo(getterm(num / 2));
		}
	}

	vector<T>multitwo(const vector<T> f) {
		vector<T>ans(2 * z_size - 1);
		vector<T>to(z_size);
		for (int j = 0; j <z_size; ++j) {
			for (int k = 0; k < z_size; ++k) {
				ans[j + k] += f[j] * f[k];
			}
		}
		for (int j = 0; j < z_size * 2 - 1; ++j) {
			for (int k = 0; k < z_size; ++k) {
				to[k] += ans[j] * terms[j][k];
			}
		}
		return to;
	}

	vector<T>plusone(const vector<T> f) {
		vector<T>t(f.size());

		for (unsigned int i = 1; i < f.size(); ++i) {
			//t[1]=f[0]+f[k-1]*f[0]
			t[i] = f[i - 1] + f.back()*terms[z_size][i];
		}
		t[0] = f.back()*terms[z_size][0];
		return t;
	}
	const int z_size;
	vector<vector<T>> terms;
};

void _main(){
  // int N; cin >> N ;
  // int N,K; cin >> N >> K ;
  // int a,b; cin >> a >> b ;
  ll N,M; cin >> N >> M ;
  vector<mint> a(M),x(M,mint(1));
  a[0] = a[M-1] = mint(1);
  Kitamasa<mint> kt(a);
  cout << kt.solve(x,N) << endl;
}

#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif

#define _USE_MATH_DEFINES

#include <stdio.h>
#include <iostream>
#include <vector>
#include <unordered_map>
#include <stack>
#include <list>
#include <math.h>
#include <map>
#include <functional>
#include <string>
#include <algorithm>
#include <queue>
#include <set>
#include <bitset>
#include <iomanip>

using namespace std;

template<class T> ostream& operator<<(ostream& os, const vector<T>& v) {
	for (auto i = begin(v); i != end(v); i++) os << *i << (i == end(v) - 1 ? "" : " "); return os;
}
template<class T> istream& operator>>(istream& is, vector<T>& v) {
	for (auto i = begin(v); i != end(v); i++) is >> *i; return is;
}

#define MOD (1000000007)

int mod = MOD;
struct ModNum
{
	int num;

	ModNum(int x) : num(x) {
//		mod = MOD;
	}

	ModNum operator+ (const ModNum &other) const
	{
		int new_val = num + other.num;
		if (new_val < mod)
		{
			return ModNum(new_val);
		}
		else
		{
			return ModNum(new_val - mod);
		}
	}

	ModNum& operator+= (const ModNum &other)
	{
		int new_val = num + other.num;
		if (new_val < mod)
			num = new_val;
		else
			num = new_val - mod;
		return *this;
	}

	ModNum operator* (const ModNum &other) const
	{
		long long new_val = (long long)num * other.num;
		if (new_val < mod)
			return ModNum(new_val);
		else
			return ModNum(new_val % mod);
	}

	operator int&(){
		return num;
	}

	operator int() const{
		return num;
	}
};

struct Matrix
{
	int rows, cols;
	vector<vector<ModNum>> matrix;
	Matrix(int rows, int cols)
	{
		this->cols = cols;
		this->rows = rows;
		matrix = vector<vector<ModNum>>(rows, vector<ModNum>(cols, 0));
	}

	Matrix multiply(const Matrix &other)
	{
		Matrix ans(rows, other.cols);
		for (int row = 0; row < rows; row++)
		{
			for (int col = 0; col < other.cols; col++)
			{
				for (int k = 0; k < cols; k++)
				{
					ans.matrix[row][col] += matrix[row][k] * other.matrix[k][col];
				}
			}
		}

		return ans;
	}

	Matrix pow(long long exp)
	{
		if (exp == 1)
			return *this;
		if (exp % 2 == 0)
		{
			Matrix tmp = pow(exp / 2);
			return tmp.multiply(tmp);
		}
		else
		{
			Matrix tmp = pow(exp - 1);
			return multiply(tmp);
		}
	}
};

int main()
{
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	cin.tie(NULL);
	ios_base::sync_with_stdio(false);
	cout.tie(NULL);

	long long n;
	int m;
	cin >> n >> m;

	if (n == 1)
	{
		cout << 1;
		return 0;
	}
	Matrix matr(m, m);
	for (int i = 1; i < m; i++)
	{
		matr.matrix[i][i - 1] = 1;
	}

	matr.matrix[0][0] = 1;
	matr.matrix[0][m - 1] = 1;

	Matrix pow_matr = matr.pow(n - 1);

	Matrix base(1, m);
	base.matrix[0][0] = 1;
	base.matrix[0][m - 1] = 1;

	cout << base.multiply(pow_matr).matrix[0][0];

	return 0;
}

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;

#define fill(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define sz(x) (int)x.size()
#define F first
#define S second
#define FOR(i,a,b) for(int i = a; i<=b; ++i)
#define NFOR(i,a,b) for(int i = a; i>=b; --i)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
const ll INF = 1e18;
const ll mod = 1e9+7;
const ll mod2 = mod*mod;
const int N = 1e5+10;

const int SZ=110;
int actualSize;

ll res[SZ][SZ];
struct matrix
{
	ll arr[SZ][SZ];

	void makezeros()
	{
		for(int i=0;i<actualSize;i++)
		for(int j=0;j<actualSize;j++)
		arr[i][j]=0;
	}

	void base()
	{
		makezeros();
		arr[0][0] = 1;
		arr[0][actualSize-1] = 1;
		for(int i=1;i<actualSize;i++)
		arr[i][i-1] = 1;
	}

	void makeiden()
	{
		makezeros();
		for(int i=0;i<actualSize;i++)
		{
			arr[i][i] = 1;
		}
	}

	ll answer(){
		ll ans = 0;
		for(int i=0;i<actualSize;i++)
		ans+=arr[0][i];

		ans%=mod;
		if(ans<0)
		ans+=mod;

		return ans;
	}

	void add(const matrix &o)
	{
		for(int i=0;i<actualSize;i++)
		{
			for(int j=0;j<actualSize;j++)
			{
				arr[i][j] = arr[i][j] + o.arr[i][j];
				if(arr[i][j]>=mod)
				arr[i][j]-=mod;
			}
		}
	}

	void mult(const matrix &o)
	{
		for(int i=0;i<actualSize;i++)
		{
			for(int j=0;j<actualSize;j++)
			{
				res[i][j] = 0;
				for(int k=0;k<actualSize;k++)
				{
					res[i][j] += arr[i][k]*o.arr[k][j];
					if(res[i][j]>=mod2)
					res[i][j]-=mod2;
				}
			}
		}

		for(int i=0;i<actualSize;i++)
		for(int j=0;j<actualSize;j++)
		arr[i][j]=res[i][j]%mod;
	}

};

matrix power(matrix& a, ll b)
{
	matrix ret;
	ret.makeiden();

	if(b<=0)
	return ret;

	while(b)
	{
		if(b & 1)
		{
			ret.mult(a);
		}
		a.mult(a);
		b >>= 1;
	}
	return ret;
}

int main(){
  fast;

  ll n;
  cin>>n>>actualSize;

  matrix mat;

  mat.base();
  mat = power(mat,n-actualSize+1);
  cout<<mat.answer()<<endl;

  return 0;
}

#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")
#pragma GCC optimize("section-anchors")
#pragma GCC optimize("profile-values,profile-reorder-functions,tracer")
#pragma GCC optimize("vpt")
#pragma GCC optimize("rename-registers")
#pragma GCC optimize("move-loop-invariants")
#pragma GCC optimize("unswitch-loops")
#pragma GCC optimize("function-sections")
#pragma GCC optimize("data-sections")
#pragma GCC optimize("branch-target-load-optimize")
#pragma GCC optimize("branch-target-load-optimize2")
#pragma GCC optimize("btr-bb-exclusive")
#include <iomanip>
#include <cstdio>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <ctime>
#include <random>
#include <queue>
#include <bitset>
#include <iostream>
#include <complex>
#include <stdio.h>
#include <chrono>
#include <math.h>
// #include <priority_queue>

// #include <bits/stdc++.h>

#pragma warning(disable : 4996)

using namespace std;

const int MAXN = 2e5 + 10;
const double EPS = 1e-7;
const long long p = 43;
const long long obrp = 510729669;
const unsigned long long INF = (1 << 30) - 1 + (1 << 30);
const int MOD = 1e9 + 7;
const long long half = (MOD + 1) / 2;
const double pi = acos(-1);

#ifdef _DEBUG
double mytime;
#endif

long long n, m;

struct matr {
	vector < vector < long long > > a;

	matr(int n = 0) {
		for (int i = 0; i < n; i++) {
			a.push_back(vector < long long >());
			for (int j = 0; j < n; j++) {
				if (i == j) {
					a.back().push_back(1);
				}
				else {
					a.back().push_back(0);
				}
			}
		}
	}

	int size() const {
		return m;
	}

	vector < long long > &operator [] (const int &x) {
		return a[x];
	}

	/*vector < long long > operator [] (const int &x) const {
		return a[x];
	}*/

	friend matr operator * (matr &a, matr &b) {
		matr ans;
		ans.a.resize(m, vector < long long > (m, 0));
		long long tmp;
		for (int i = 0; i < m; i++) {
			//ans.a.push_back(vector < long long >());
			for (int j = 0; j < m; j++) {
				//ans.a.back().push_back(0);
				for (int k = 0; k < m; k++) {
					ans[i][j] = (a[i][k] * b[k][j] + ans[i][j]) % MOD;
				}

			}
		}
		return ans;
	}
};

matr binpow(matr a, long long p) {
	matr r = a;
	p--;
	while (p > 0) {
		if (p & 1)
			r = r * a;
		p >>= 1;
		a = a * a;
	}
	return r;
}

/*matr binpow(const matr &x, long long st) {
	if (st == 0) return matr(m);
	if (st % 2 == 0) {
		matr tmp = binpow(x, st / 2);
		return tmp * tmp;
	}
	return binpow(x, st - 1) * x;
}*/

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	mytime = clock();
#endif
#ifndef _DEBUG
	/*freopen("caves.in", "r", stdin);
	freopen("caves.out", "w", stdout);*/
#endif

	srand(time(0));
	//srand(322);
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	// CODE

	cin >> n >> m;
	matr beg(1);
	beg[0].resize(m, 1);
	matr tmp(m);
	for (int i = 0; i < m; i++) {
		for (int j = 0; j < m; j++) {
			if (i - 1 == j) {
				tmp[i][j] = 1;
			}
			else {
				tmp[i][j] = 0;
			}
		}
	}
	tmp[0][m - 1] = 1;
	tmp[m - 1][m - 1] = 1;
	tmp = binpow(tmp, n);
/*	for (int i = 0; i < m; i++) {
		for (int j = 0; j < m; j++) {
			cout << tmp[i][j] << " ";
		}
		cout << "\n";
	}*/
	long long ans = 0;
	for (int i = 0; i < m; i++) {
		ans += tmp[i][0];
	}
	cout << ans % MOD;

	// CODE

#ifdef _DEBUG
	mytime = clock() - mytime;
	cout << "\n\n" << fixed << setprecision(15) << mytime / CLOCKS_PER_SEC * 1000 << "\n";
	//printf("\n\n%llf ms", mytime / CLOCKS_PER_SEC * 1000);
	//system("pause");
#endif
	return 0;
}

#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <cassert>
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

int _,n;
namespace linear_seq {
    const int N=10010;
    ll res[N],base[N],_c[N],_md[N];

    vector<int> Md;
    void mul(ll *a,ll *b,int k) {
        rep(i,0,k+k) _c[i]=0;
        rep(i,0,k) if (a[i]) rep(j,0,k) _c[i+j]=(_c[i+j]+a[i]*b[j])%mod;
        for (int i=k+k-1;i>=k;i--) if (_c[i])
            rep(j,0,SZ(Md)) _c[i-k+Md[j]]=(_c[i-k+Md[j]]-_c[i]*_md[Md[j]])%mod;
        rep(i,0,k) a[i]=_c[i];
    }
    int solve(ll n,VI a,VI b) {
        ll ans=0,pnt=0;
        int k=SZ(a);
        assert(SZ(a)==SZ(b));
        rep(i,0,k) _md[k-1-i]=-a[i];_md[k]=1;
        Md.clear();
        rep(i,0,k) if (_md[i]!=0) Md.push_back(i);
        rep(i,0,k) res[i]=base[i]=0;
        res[0]=1;
        while ((1ll<<pnt)<=n) pnt++;
        for (int p=pnt;p>=0;p--) {
            mul(res,res,k);
            if ((n>>p)&1) {
                for (int i=k-1;i>=0;i--) res[i+1]=res[i];res[0]=0;
                rep(j,0,SZ(Md)) res[Md[j]]=(res[Md[j]]-res[k]*_md[Md[j]])%mod;
            }
        }
        rep(i,0,k) ans=(ans+res[i]*b[i])%mod;
        if (ans<0) ans+=mod;
        return ans;
    }
    VI BM(VI s) {
        VI C(1,1),B(1,1);
        int L=0,m=1,b=1;
        rep(n,0,SZ(s)) {
            ll d=0;
            rep(i,0,L+1) d=(d+(ll)C[i]*s[n-i])%mod;
            if (d==0) ++m;
            else if (2*L<=n) {
                VI T=C;
                ll c=mod-d*powmod(b,mod-2)%mod;
                while (SZ(C)<SZ(B)+m) C.pb(0);
                rep(i,0,SZ(B)) C[i+m]=(C[i+m]+c*B[i])%mod;
                L=n+1-L; B=T; b=d; m=1;
            } else {
                ll c=mod-d*powmod(b,mod-2)%mod;
                while (SZ(C)<SZ(B)+m) C.pb(0);
                rep(i,0,SZ(B)) C[i+m]=(C[i+m]+c*B[i])%mod;
                ++m;
            }
        }
        return C;
    }
    int gao(VI a,ll n) {
        VI c=BM(a);
        c.erase(c.begin());
        rep(i,0,SZ(c)) c[i]=(mod-c[i])%mod;
        return solve(n,c,VI(a.begin(),a.begin()+SZ(c)));
    }
};
ll f[205];
int main() {
    ll n,m;
    cin>>n>>m;
    for(int i=1;i<m;i++) f[i]=1;
    f[m]=2;
    for(int i=m+1;i<=200;i++)
	f[i]=(f[i-1]+f[i-m])%mod;
    vector<int> v;
    for(int i=1;i<=200;i++)
	v.push_back(f[i]);
   cout<< linear_seq::gao(v,n-1);
}

#include<bits/stdc++.h>
using namespace std;

#define mod 1000000007LL
#define crap ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define lli long long
#define pa pair<int,int>
#define pal pair<lli,lli>
#define vi vector< int >
#define vli vector< lli >
#define vpa vector< pa >
#define vpal vector< pal >
#define fi first
#define se second
#define pb emplace_back

#define FOR(i,n) for(int i=0;i<n;i++)
#define FORR(x,v) for(auto x : v)
#define all(v) v.begin(), v.end()
#define sz(a) (int)(a.size())
#define max3(x,y,z) max(max(x,y),z)
#define min3(x,y,z) min(min(x,y),z)
#define perc %

lli N, ans = 0;
int M;

struct mat{
    lli v[101][101];
    mat(){
        FOR(i, M) FOR(j, M) v[i][j] = 0;
    }
    void init(){
        FOR(i, M-1) v[i][i+1] = 1;
        v[M-1][0] = v[M-1][M-1] = 1;
    }
    void iden(){
        FOR(i, M) v[i][i]=1;
    }
};

mat operator *(mat l, mat r){
    mat ans;
    FOR(i, M) FOR(k, M) FOR(j, M) {
        ans.v[i][j] += l.v[i][k] * r.v[k][j];
        if(ans.v[i][j] >= mod*mod) ans.v[i][j] -= mod*mod;
    }
    FOR(i, M) FOR(j, M) if(ans.v[i][j] >=  mod) ans.v[i][j] %= mod;
    return ans;
}

mat modpow(lli p){
    if(!p) {
        mat temp;
        temp.iden();
        return temp;
    }
    if(p&1){
        mat temp;
        temp.init();
        return temp*modpow(p-1);
    }
    mat temp = modpow(p>>1);
    return temp*temp;
}

int main(int argc, char **argv)
{
    crap;
    cin>>N>>M;
    mat temp = modpow(N);
    FOR(i, M) ans += temp.v[0][i];
    cout<<ans % mod<<endl;
}

#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0),cin.tie(0);
#define ll long long
#define int ll
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
#define all(n) (n).begin(),(n).end()
#pragma GCC optimize("O3")
using namespace std;
ll n,m;
int num;
const ll mod = 1000000007;

struct mat{
	ll a[205][205];
	mat(){
		memset(a,0,sizeof(a));
	}
	mat operator *(const mat &b){
		mat c;
		for(int i=0;i<num;i++){
			for(int k=0;k<num;k++){
				for(int j=0;j<num;j++){
					c.a[i][j] = (c.a[i][j]+ a[i][k] * b.a[k][j])%mod;
				}
			}
		}
		return c;
	}
};

signed main(){
	IOS;
	cin>>n>>m;
	num = m*2-2;
	mat ori;
	for(int i=1;i<=m;i++){
		ori.a[0][2*m-2-i] = 1;
	}
	for(int i=m-3;i>=0;i--){
		ori.a[0][i] = ori.a[0][i+1]+1;
	}
	mat tra;
	for(int i=0;i<m;i++){
		tra.a[2*m-3-i][0] = 1;
	}
	for(int j=1;j<2*m-2;j++){
		tra.a[j-1][j] = 1;
	}

	while(n){
		if(n&1){
			mat c;
			for(int k=0;k<num;k++){
				for(int j=0;j<num;j++){
					c.a[0][j] = (c.a[0][j]+ ori.a[0][k] * tra.a[k][j])%mod;
				}
			}
			ori = c;
		}
		tra = tra*tra;
		n>>=1;
	}

	cout<<ori.a[0][2*m-3]<<'\n';
}

#include<iostream>
#include<algorithm>
#include<vector>
#define ll long long
using namespace std;

const ll mod = 1e9 + 7;
ll N; ll M;

typedef vector<ll> vec;

typedef vector<vec> mat;

mat mutil(mat& a, mat& b)
{
	mat c(M, vec(M));
	for (int i = 0; i < M; i++)
	{
		for (int k = 0; k < M; k++)
		{
			if (a[i][k] == 0)continue;
			for (int j = 0; j < M; j++)
			{
				c[i][j] += (a[i][k] % mod * b[k][j] % mod) % mod;
				c[i][j] = (c[i][j] % mod + mod) % mod;
			}
		}
	}
	return c;
}

mat POW(ll x, mat& a)
{
	mat s(M, vec(M));
	for (int i = 0; i < M; i++) s[i][i] = 1;
	while (x != 0)
	{
		if ((x & 1) == 1)
		{
			s = mutil(s, a);
		}
		a = mutil(a, a);
		x >>= 1;
	}
	return s;
}

int main()
{
	cin >> N >> M;
	mat a(M, vec(M));
	vec b(M);
	a[0][0] = 1; a[0][M - 1] = 1;
	for (int i = 1; i < M; i++)
	{
		a[i][i - 1] = 1;
	}
	for (int i = 0; i < M - 1; i++) b[i] = 1;
	b[M - 1] = 2;

	if (N <= M) { cout << b[N - 1]; return 0; }
	else
	{
		a = POW(N - M, a);
		ll ans = 0;
		for (int i = 0; i < M; i++)
		{
			ans += (a[0][i] % mod * b[M - i - 1] % mod) % mod;
			ans = (ans % mod + mod) % mod;
		}
		cout << ans;
	}
	return 0;
}

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;

#define fill(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define sz(x) (int)x.size()
#define F first
#define S second
#define FOR(i,a,b) for(int i = a; i<=b; ++i)
#define NFOR(i,a,b) for(int i = a; i>=b; --i)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
const ll INF = 1e18;
const ll mod = 1e9+7;
const int N = 1e5+10;

const int SZ=110;
int actualSize;

ll add(ll a, ll b)
{
	return (a+b) % mod;
}

ll mult(ll a, ll b)
{
	return (a*b) % mod;
}

struct matrix
{
	ll arr[SZ][SZ];

	void makezeros()
	{
		for(int i=0;i<SZ;i++)
		for(int j=0;j<SZ;j++)
		arr[i][j]=0;
	}

	void base()
	{
		makezeros();
		arr[0][0] = 1;
		arr[0][actualSize-1] = 1;
		for(int i=1;i<actualSize;i++)
		arr[i][i-1] = 1;
	}

	void makeiden()
	{
		makezeros();
		for(int i=0;i<SZ;i++)
		{
			arr[i][i] = 1;
		}
	}

	int answer(){
		ll ans = 0;
		for(int i=0;i<actualSize;i++)
		ans+=arr[0][i];

		return add(ans,0);
	}

	matrix operator + (const matrix &o) const
	{
		matrix res;
		for(int i=0;i<SZ;i++)
		{
			for(int j=0;j<SZ;j++)
			{
				res.arr[i][j] = add(arr[i][j], o.arr[i][j]);
			}
		}
		return res;
	}

	matrix operator * (const matrix &o) const
	{
		matrix res;
		for(int i=0;i<SZ;i++)
		{
			for(int j=0;j<SZ;j++)
			{
				res.arr[i][j] = 0;
				for(int k=0;k<SZ;k++)
				{
					res.arr[i][j] = add(res.arr[i][j] , mult(arr[i][k] , o.arr[k][j]));
				}
			}
		}
		return res;
	}
};

matrix power(matrix a, ll b)
{
	matrix ret;
	ret.makeiden();

	if(b<=0)
	return ret;

	while(b)
	{
		if(b & 1)
		{
			ret = ret * a;
		}
		a = a * a;
		b >>= 1;
	}
	return ret;
}

int main(){
  fast;

  ll n;
  cin>>n>>actualSize;

  matrix mat;

  mat.base();
  mat = power(mat,n-actualSize+1);
  cout<<mat.answer()<<endl;

  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) x.begin(), x.end()
#define boost                     \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)
#define ff first
#define ss second
#define mod 1000000007
#define eb emplace_back
#define pb push_back
#define For(i, a, b) for (i = a; i < b; i++)
#define gcd __gcd
#define double long double
#define gc getchar_unlocked
#define endl "\n"
#define sz(x) x.size()

ll T[105][105];
ll m, n;

void multiply(long long res[][105], long long T[][105])
{
    long long ans[m + 1][105];
    memset(ans,0,sizeof ans);
    int i, j, k;
    for (i = 0; i < m; i++)
    {
        for (k = 0; k < m; k++)
        {
            // ans[i][j] = 0;
            for (j = 0; j < m; j++)
            {
                ans[i][j] += res[i][k] * T[k][j];
                if(ans[i][j]>=mod)
                ans[i][j] %= mod;
            }
        }
    }
    for (i = 0; i < m; i++)
        for (j = 0; j < m; j++)
            res[i][j] = ans[i][j];
}

void fast_exp(long long final_mul[][105], long long power, long long m)
{
    long long res[m + 1][105], b[m + 1][105];
    int i, j;
    for (i = 0; i < m; i++)
        for (j = 0; j < m; j++)
            res[i][j] = T[i][j];
    // cout << power << endl;
    power--;
    // cout << power << endl;
    // printf("%lld\n",power);
    while (power > 0)
    {
        if (power & 1)
        {
            multiply(res, T);
        }

        power >>= 1;
        multiply(T, T);
    }
    // return res;
    for (i = 0; i < m; i++)
        for (j = 0; j < m; j++)
            final_mul[i][j] = res[i][j];
}

int main(void)
{
    // boost;
    ll t, i, j;
    string s;
    cin >> n >> m;
    if (n < m)
    {
        cout << 1;
        return 0;
    }
    T[0][0] = T[0][m - 1] = 1;
    for (i = 1; i < m; i++)
        T[i][i - 1] = 1;
    // for (i = 0; i < m; i++)
    // {
    //     for (j = 0; j < m; j++)
    //         cout << T[i][j] << " ";
    //     cout << endl;
    // }

    long long final_mul[m + 1][105];
    fast_exp(final_mul, n - m + 1, m);
    ll ans = 0;
    // for (i = 0; i < m; i++)
    // {
    //     for (j = 0; j < m; j++)
    //         cout << final_mul[i][j] << " ";
    //     cout << endl;
    // }
    for (i = 0; i < m; i++)
    {
        ans += final_mul[0][i];
        if (ans >= mod)
            ans %= mod;
    }
        cout << ans;
        return 0;
    }

#include<bits/stdc++.h>
#define Mod 1000000007
using namespace std;

typedef long long LL;

struct Matrix
{
	int n, m, a[103][103];

	Matrix(){}
	Matrix(int _n, int _m)
	{
		n = _n, m = _m;
		memset(a, 0, sizeof(a));
	}

	Matrix operator * (Matrix b)
	{
		int N = n, R = m, M = b.m;
		Matrix c = Matrix(N, M);
		for(int i=1; i<=N; ++i)
		for(int j=1; j<=M; ++j)
		for(int k=1; k<=R; ++k)
			c.a[i][j] = (c.a[i][j] + (LL)a[i][k] * b.a[k][j] % Mod) % Mod;
		return c;
	}
};

Matrix Ksm(Matrix a, LL b)
{
	if(b == 1) return a;
	Matrix temp = Ksm(a, b >> 1);
	temp = temp * temp;
	if(b & 1) temp = temp * a;
	return temp;
}

int main()
{
	LL n;
	int m;
	cin >> n >> m;

	Matrix A = Matrix(1, m), B = Matrix(m, m);

	for(int i=1; i<m; ++i) A.a[1][i] = 1;
	A.a[1][m] = 2;

	for(int i=2; i<=m; ++i) B.a[i][i-1] = 1;
	B.a[m][m] = B.a[1][m] = 1;

	if(n <= m) cout << A.a[1][n];
	else
	{
		n -= m;
		B = Ksm(B, n);
		A = A * B;
		cout << A.a[1][m];
	}
}

#include <bits/stdc++.h>
#define lli long long int
#define mod 1000000007

using namespace std;

vector<vector<lli> > matmul(vector<vector<lli> > a, vector<vector<lli> > b, lli M, vector<vector<lli> > c){

    for (lli i = 0; i < M; ++i)
    {
        for (lli j = 0; j < M; ++j)
        {
            for (lli k = 0; k < M; ++k)
            {
                c[i][j] += ((a[i][k] % mod) * (b[k][j] % mod)) % mod;
            }
        }
    }

    return c;
}

int main(){
    ios_base::sync_with_stdio(false);
    #ifndef ONLINE_JUDGE
        freopen("in.txt","r",stdin);
    #endif

    lli N, M; cin >> N >> M;

    vector<vector<lli> > a;
    a.resize(M);
    for (lli i = 0; i < M; ++i) a[i].resize(M);

    vector<vector<lli> > c;
    c.resize(M);
    for (lli i = 0; i < M; ++i) c[i].resize(M);

    vector<vector<lli> > result;
    result.resize(M);
    for (lli i = 0; i < M; ++i) result[i].resize(M);
    for (lli i = 0; i < M; i++) result[i][i] = 1;

    a[0][M-1] = 1; a[M-1][M-1] = 1;
    for (lli i = 0; i < M-1; ++i)
    {
        a[i+1][i] = 1;
    }

    N = N - M + 1;

    while(N > 0){
        if(N % 2 == 1){
            result = matmul(result, a, M, c);
        }
        a = matmul(a, a, M, c);
        N /= 2;
    }

    lli ans = 0;
    for (int i = 0; i < M; ++i)
    {
        ans = ((ans % mod) + (result[i][M-1] % mod)) % mod;
    }

    cout << ans << endl;

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int D = 105;
const int mod = 1000000007;
struct Matrix{
    int a[D][D];
    Matrix (){memset(a,0,sizeof(a));}
};
int add(int x,int y){
    x += y;
    if(x >= mod){
        x -= mod;
    }
    return x;
}
int mult(int x,int y){
    return ((ll)x*y)%mod;
}
Matrix operator * (Matrix &a,Matrix &b){
    Matrix ans;
    for(int i = 0; i < D; i++){
        for(int k = 0; k < D; k++){
            for(int j = 0; j < D; j++){
                ans.a[i][j] = add(ans.a[i][j],mult(a.a[i][k],b.a[k][j]));
            }
        }
    }
    return ans;
}
Matrix mpow(Matrix a,ll p){
    Matrix ans;
    for(long i = 0; i < D; i++){
        ans.a[i][i] = 1;
    }
    while(p){
        if(p&1){
            ans = ans*a;
        }
        a = a*a;
        p >>= 1;
    }
    return ans;
}
int main(){
    ll n;
    int m;

    cin >> n >> m;
    if(n < m){
        cout << "1" << endl;
        return 0;
    }
    if(n == m){
        cout << "2" << endl;
        return 0;
    }
    Matrix base;
    base.a[0][0] = 1;
    base.a[0][m-1] = 1;
    for(long i = 1; i < D; i++){
        base.a[i][i-1] = 1;
    }
    base = mpow(base,n-m);
    Matrix nesto;
    nesto.a[0][0] = 2;
    for(long i = 1; i < m; i++){
        nesto.a[i][0] = 1;
    }
    base = base*nesto;
    cout << base.a[0][0] << endl;
}

#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define MOD 1000000007
#define MOD9 1000000009
#define pi 3.1415926535
#define ms(s, n) memset(s, n, sizeof(s))
#define prec(n) fixed<<setprecision(n)
#define eps 0.000001
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define bolt ios::sync_with_stdio(0)
#define light cin.tie(0);cout.tie(0)
#define forr(i,p,n) for(ll i=p;i<n;i++)
#define MAXN 1000003
typedef long long ll;
using namespace std;
ll mult(ll a,ll b, ll p=MOD){return ((a%p)*(b%p))%p;}
ll add(ll a, ll b, ll p=MOD){return (a%p + b%p)%p;}
ll fpow(ll n, ll k, ll p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n%p; n = n * n%p;} return r;}
ll inv(ll a, ll p = MOD) {return fpow(a, p - 2, p);}
ll inv_euclid(ll a, ll m = MOD){ll m0 = m;ll y = 0, x = 1;if (m == 1)return 0;while (a > 1){ll q = a / m;ll t = m;m = a % m, a = t;t = y;y = x - q * y;x = t;}if (x < 0)x += m0;return x;}

ll bin[103][103];

void mult_mat(ll m, ll ans[][100], ll bin[][100]){
    ll mult[m][m];
    forr(i,0,m){
        forr(j,0,m){
            mult[i][j]=0;
            forr(k,0,m){
                mult[i][j]+=ans[i][k]*bin[k][j];
                if(mult[i][j]>=MOD){
                    mult[i][j]%=MOD;
                }
            }
        }
    }
    forr(i,0,m){
        forr(j,0,m){
            ans[i][j]=mult[i][j];
        }
    }
}

void pow_mat(ll n, ll fin[][100], ll m){
    ll ans[m][100];
    ll b[m][100];
    forr(i,0,m){
        forr(j,0,m){
            ans[i][j]=bin[i][j];
            b[i][j]=bin[i][j];
        }
    }
    n--;
    while(n>0){
        if(n%2==1){
            mult_mat(m,ans,b);
            n--;
        }else{
            n=n/2;
            mult_mat(m,b,b);
        }
    }
    forr(i,0,m){
        forr(j,0,m){
            fin[i][j]=ans[i][j];
        }
    }
}

int main(){
    bolt;
    ll n,m;
    cin>>n>>m;
    bin[0][0]=1;
    bin[0][m-1]=1;
    for(ll i=1;i<m;i++){
        bin[i][i-1]=1;
    }
    if(n<m){
        cout<<1<<"\n";
    }else{
        ll fin[m+1][100];
        pow_mat(n-m+1,fin,m);
        ll ans=0;
        forr(i,0,m){
            ans+=fin[0][i];
            if(ans>=MOD){
                ans-=MOD;
            }
        }
        cout<<ans<<"\n";
    }
}

#include <bits/stdc++.h>

#define REP(i,begin,end) for(int i=begin;i<=end;i++)

using namespace std;

typedef long long int lli;
typedef vector<vector<lli>> matrix;

#define MAXM 102
#define MOD (lli)1000000007
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);

int m;

matrix mult(matrix A, matrix B){
matrix C(m+1,vector<lli>(m+1));
REP(i,1,m) REP(j,1,m) REP(k,1,m) C[i][j] = (C[i][j] + (A[i][k]*B[k][j])%MOD)%MOD;
return C;
}

matrix expM(matrix A, lli n){
	if(n == 1) return A;
	else if((n%2) == 1) return mult(A,expM(A,n-1));
	else{
		matrix aux = expM(A,n/2);
        return mult(aux,aux);
	}
}

lli sol(lli N){
if(N < m) return 1;
else if(N == m) return 2;
else{
	matrix T(m+1,vector<lli>(m+1));
	REP(i,1,m) REP(j,1,m) T[i][j] = 0;
	REP(i,1,m-1) T[i][i+1] = 1;
	T[m][1] = 1;
	T[m][m] = 1;
	matrix expT = expM(T,N-1);
	lli ans = 0;
	REP(i,1,m-1) ans = (ans + expT[1][i])%MOD;
	ans = (ans + (2*expT[1][m])%MOD)%MOD;
	return ans;
}
}

int main(){
fio
lli n;
cin >> n >> m;
cout << sol(n) << endl;
return 0;
}

#include<cstdio>
#include<algorithm>
#include<cmath>
#define MOD 1000000007
using namespace std;
long long n, m;
long long init[105];
long long matrix[99][105][105];
long long mat[105][105], dum[105][105];
void multiply_matrix(long long x) {
	long long ex=1,exx=1;
	int i, j, k;
	while (ex*2 <= x) {
		ex *= 2; exx++;
		for (i = 1; i <= m; i++) {
			for (j = 1; j <= m; j++) {
				for (k = 1; k <= m; k++) {
					matrix[exx][i][j] += matrix[exx - 1][i][k] * matrix[exx - 1][k][j];
					matrix[exx][i][j] %= MOD;
				}
			}
		}
	}
	for (i = 1; i <= m; i++) mat[i][i] = 1;
	exx = 1;
	while (x > 0) {
		if (x % 2 == 1) {
			for (i = 1; i <= m; i++) {
				for (j = 1; j <= m; j++) {
					dum[i][j] = mat[i][j];
					mat[i][j] = 0;
				}
			}
			for (i = 1; i <= m; i++) {
				for (j = 1; j <= m; j++) {
					for (k = 1; k <= m; k++) {
						mat[i][j] += dum[i][k] * matrix[exx][k][j];
						mat[i][j] %= MOD;
					}
				}
			}
		}
		x /= 2;
		exx++;
	}
}
int main() {
	scanf("%lld%lld", &n, &m);
	if (n < m) {
		printf("1");
		return 0;
	}
	int i;
	for (i = 0; i < m; i++) init[i] = 1;
	for (i = 1; i < m ; i++) {
		matrix[1][i][i + 1] = 1;
	}
	matrix[1][m][1] = 1; matrix[1][m][m] = 1;
	multiply_matrix(n-m+1);
	long long ans = 0;
	for (i = 1; i <= m; i++) {
		ans += mat[m][i];
		ans %= MOD;
	}
	printf("%lld", ans);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int>   II;
typedef vector< II >      VII;
typedef vector<int>     VI;
typedef vector< VI > 	VVI;
typedef long long int 	LL;
typedef vector<LL> 		VL;
typedef unsigned long long int ULL;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define ALL(a) a.begin(),a.end()
#define SET(a,b) memset(a,b,sizeof(a))
#define LET(x,a) __typeof(a) x(a)

#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
//Works for forward as well as backward iteration

#define gu getchar
#define pu putchar
#define si(n) cin>>n
#define dout(n) cout<<n<<"\n"
//# define M_PI           3.14159265358979323846264338327950288

#define DRT() int t; si(t); while(t--)

#define PlUSWRAP(index,n) index = (index+1)%n		//index++; if(index>=n) index=0
#define MINUSWRAP(index,n) index = (index + n -1)%n 	//index--; if(index<0) index=n-1
#define ROUNDOFFINT(d) d = (int)((double)d + 0.5)	//Round off d to nearest integer

#define FLUSHN while(gu()!='\n')
#define FLUSHS while(gu()!=' ')

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define off ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

// set_name.find_by_order(k) It returns to an iterator to the kth element (counting from zero) in the set in O(logn) time
// set_name.order_of_key(k) It returns to the number of items that are strictly smaller than our item k in O(logn) time.
LL n,m;
VVI res;
VVI mat;
LL mod = (LL)(1e9 + 7);
// modular mutliplication
LL mm(LL a,LL b)
{
    if (a == 0 || b < mod / a){
    	LL t = a*b;
    	if(t >= mod)
    		t -= mod;
        return t;
    }
    LL sum=0;
    while(b>0)
    {
        if(b&1){
            sum = (sum + a);
            if(sum >= mod)
            	sum -= mod;
        }
        a = (a << 1);
        if(a >= mod)
        	a -= mod;
        b>>=1;
    }
    return sum;
}
inline LL modmult(LL a, LL b){
	return (a*b) % mod;
}
// Matrix Multiply
void multiply(LL a, VVI b){
	LL len = b.size();
	VVI ans(len, VI (len,0));
	rep(i,0,len){
		rep(k,0,len){
			rep(j,0,len){
				if(a == 1){
					ans[i][j] =(ans[i][j] +  modmult(res[i][k], b[k][j]) );
				}
				else{
					ans[i][j] =(ans[i][j] +  modmult(mat[i][k], b[k][j]) );
				}

				while(ans[i][j] >= mod){
					ans[i][j] -= mod;
				}
			}
		}
	}
	rep(i,0,len){
		rep(j,0,len){
			if(a == 1)
				res[i][j] = ans[i][j];
			else
				mat[i][j] = ans[i][j];
		}
	}
}

// Fast exponentiation
void power(LL y)
{
    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            multiply(1, mat);

        // y must be even now
        y = y>>1; // y = y/2
        	multiply(2, mat);
    }
}
int main() {
	#ifndef ONLINE_JUDGE
    freopen("../input.txt", "r", stdin);
    freopen("../output.txt", "w", stdout);
	#endif
	srand(chrono::steady_clock::now().time_since_epoch().count());
	off;
	cin>>n>>m;

	res.resize(m, VI(m, 0));
	rep(i,0,m)
	res[i][i] = 1;

	mat.resize(m, VI(m, 0));
	mat[0][0] = mat[0][m-1] = 1;
	rep(i,1,m){
		mat[i][i-1] = 1;
	}

	// just sum the top row of the obtained matrix and multiply it by two;
	// dp[0] = 1, dp[1] = 1 <---- base case --------- dp[m] = 2 = dp[0] + dp[m-1]
	if(n < m)
		cout<<1;
	else{
		LL extra = n - m + 1;
		power(extra);
		LL ans = 0;
		rep(i,0,m){
			ans = (ans + res[0][i]);
			if(ans >= mod)
				ans -= mod;
		}
		cout<<ans;
	}
  	return 0;
}

#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif

#define _USE_MATH_DEFINES

#include <stdio.h>
#include <iostream>
#include <vector>
#include <unordered_map>
#include <stack>
#include <list>
#include <math.h>
#include <map>
#include <functional>
#include <string>
#include <algorithm>
#include <queue>
#include <set>
#include <bitset>
#include <iomanip>

using namespace std;

template<class T> ostream& operator<<(ostream& os, const vector<T>& v) {
	for (auto i = begin(v); i != end(v); i++) os << *i << (i == end(v) - 1 ? "" : " "); return os;
}
template<class T> istream& operator>>(istream& is, vector<T>& v) {
	for (auto i = begin(v); i != end(v); i++) is >> *i; return is;
}

#define MOD (1000000007)

struct ModNum
{
	int num;
	int mod;

	ModNum(int x) : num(x) {
		mod = MOD;
	}

	ModNum& operator=(int other)
	{
		num = other;
		return *this;
	}

	ModNum operator+ (const ModNum &other)
	{
		int new_val = num + other.num;
		if (new_val < mod)
		{
			return ModNum(new_val);
		}
		else
		{
			return ModNum(new_val - mod);
		}
	}

	ModNum& operator+= (const ModNum &other)
	{
		int new_val = num + other.num;
		if (new_val < mod)
		{
			num = new_val;
		}
		else
		{
			num = new_val - mod;
		}
		return *this;
	}

	ModNum operator* (const ModNum &other)
	{
		long long new_val = (long long)num * other.num;
		if (new_val < mod)
		{
			return ModNum(new_val);
		}
		else
		{
			return ModNum(new_val % mod);
		}
	}
};

struct Matrix
{
	int rows, cols;
	vector<vector<ModNum>> matrix;
	Matrix(int rows, int cols)
	{
		this->cols = cols;
		this->rows = rows;
		matrix = vector<vector<ModNum>>(rows, vector<ModNum>(cols, 0));
	}

	Matrix multiply(Matrix &other)
	{
		Matrix ans(rows, other.cols);
		for (int row = 0; row < rows; row++)
		{
			for (int col = 0; col < other.cols; col++)
			{
				for (int k = 0; k < cols; k++)
				{
					ans.matrix[row][col] += matrix[row][k] * other.matrix[k][col];
				}
			}
		}

		return ans;
	}

	Matrix pow(long long exp)
	{
		if (exp == 1)
			return *this;
		if (exp % 2 == 0)
		{
			Matrix tmp = pow(exp / 2);
			return tmp.multiply(tmp);
		}
		else
		{
			Matrix tmp = pow(exp - 1);
			return multiply(tmp);
		}
	}
};

int main()
{
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	cin.tie(NULL);
	ios_base::sync_with_stdio(false);
	cout.tie(NULL);

	long long n;
	int m;
	cin >> n >> m;

	if (n == 1)
	{
		cout << 1;
		return 0;
	}
	Matrix matr(m, m);
	for (int i = 1; i < m; i++)
	{
		matr.matrix[i][i - 1] = 1;
	}

	matr.matrix[0][0] = 1;
	matr.matrix[0][m - 1] = 1;

	Matrix pow_matr = matr.pow(n - 1);

	Matrix base(1, m);
	base.matrix[0][0] = 1;
	base.matrix[0][m - 1] = 1;

	cout << base.multiply(pow_matr).matrix[0][0].num;

	return 0;
}

/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author cherrypi59
 */

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iterator>
#include <random>
#include <cassert>
#include <iomanip>
#define FOR(i, a, b) for(int (i)=(a);(i)<(b);++(i))
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FOR(i, 1, n+1)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define LEN(x) (int)(x).size()
#define DUMP(x) cout<<#x<<"="<<(x)<<endl;
#define pb push_back
#define eb emplace_back
using namespace std;
typedef long long lint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
typedef vector<int> vi;
typedef vector<lint> vl;
typedef vector<char> vc;
typedef vector<vector<int>> vii;
typedef vector<vector<lint>> vll;
typedef vector<vector<char>> vcc;
template <typename T> inline bool chmax(T &a, T b){if(a<b){a = b; return true;} return false;}
template <typename T> inline bool chmin(T &a, T b){if(a>b){a = b; return true;} return false;}
const double EPS = 1e-10;
const double PI = acos(-1);

const lint MOD = (lint)1e9 + 7;
const lint MOD2 = MOD * MOD;

struct mint {
    lint x;
    mint(lint x=0):x((x%MOD+MOD)%MOD){}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(lint t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    mint inv() const {
        return pow(MOD-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
    friend istream& operator>>(istream& in, mint& a){
        long long _v; in>>_v;
        a = mint(_v);
        return in;
    }
    friend ostream& operator<<(ostream& out, const mint& a){
        return out<<a.x;
    }
    friend bool operator==(const mint& a, const mint& b){
        return a.x == b.x;
    }
    friend bool operator!=(const mint& a, const mint& b){
        return a.x != b.x;
    }
};

typedef vector<mint> vm;
typedef vector<vector<mint>> vmm;

struct Matrix{
    int n, m;
    vector<vector<mint>> mat;
    Matrix(int _n, int _m, mint _ini=0) : n(_n), m(_m), mat(n, vector<mint>(m, _ini)) {}
    inline int row() const {return n;}
    inline int column() const {return m;}
    inline vector<mint>& operator[](int i) {
        assert(i<n);
        return mat[i];
    }
};

Matrix operator * (Matrix& A, Matrix& B){
    Matrix res(A.row(), B.column());
    REP(i, A.row()) REP(k, A.column()){
            REP(j, B.row()) res[i][j] += A[i][k] * B[k][j];
        }
    return res;
}

Matrix pow(Matrix A, lint n){
    Matrix res(A.row(), A.row());
    REP(i, A.row()) res[i][i] = 1;
    while(n){
        if(n & 1) res = res * A;
        A = A * A, n >>= 1;
    }
    return res;
}

class DMagicGems {
public:
    void solve(std::istream& in, std::ostream& out){
        ios_base::sync_with_stdio(false);
        in.tie(nullptr), out.tie(nullptr);
        lint N, M;
        in>>N>>M;
        if(N<M){
            out<<"1\n";
            return;
        }
        Matrix A(M, M);
        A[0][0] = A[0][M-1] = 1;
        RREP(i, M-1) A[i][i-1] = 1;
        A = pow(A, N-M+1);
        mint ans = 0;
        REP(i, M) ans += A[0][i];
        out<<ans<<'\n';
    }
};

int main() {
	DMagicGems solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pii pair<int,int>
inline ll read()
{
    ll x=0;
    bool pos=1;
    char ch=getchar();
    for(;!isdigit(ch);ch=getchar())
        if(ch=='-')
            pos=0;
    for(;isdigit(ch);ch=getchar())
        x=x*10+ch-'0';
    return pos?x:-x;
}
const int MAXM=110;
const int P=1e9+7;
inline int add(int a,int b)
{
    return (a + b) % P;
}
inline int mul(int a,int b)
{
    return 1LL * a * b % P;
}
ll n;
int m;
struct Matrix{
    int a[MAXM][MAXM];
    Matrix()
        {
            for(int i=1;i<=m;++i)
                for(int j=1;j<=m;++j)
                    a[i][j]=0;
        }
    Matrix operator * (const Matrix &rhs) const
        {
            Matrix res;
            for(int k=1;k<=m;++k)
                for(int i=1;i<=m;++i) if(a[i][k])
                    for(int j=1;j<=m;++j) if(rhs.a[k][j])
                        res.a[i][j]=add(res.a[i][j],mul(a[i][k],rhs.a[k][j]));
            return res;
        }
};
Matrix fpow(Matrix x,ll b)
{
    Matrix res;
    for(int i=1;i<=m;++i)
        res.a[i][i]=1;
    while(b)
        {
            if(b&1)
                res=res*x;
            x=x*x;
            b>>=1;
        }
    return res;
}
int main()
{
    n=read(),m=read();
    if(n<m)
        return puts("1")&0;
    Matrix st;
    for(int i=1;i<=m;++i)
        st.a[i][1]=1;
    Matrix trans;
    trans.a[1][1]=trans.a[1][m]=1;
    for(int i=2;i<=m;++i)
        trans.a[i][i-1]=1;
    st=fpow(trans,1LL*(n-m+1))*st;
    cout<<st.a[1][1];
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define Sheryang main
#define TYPE int
const int maxn=1e6+7;
typedef long long ll;
const int mod=1e9+7;
void Smax(TYPE &a,TYPE b){if(a<b) a=b;}
void Smin(TYPE &a,TYPE b){if(a>b) a=b;}
///#define getchar()(p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++)
///char buf[(1 << 21) + 1], *p1 = buf, *p2 = buf;
#define IO cin.tie(0),ios::sync_with_stdio(false);
#define pi acos(-1)
#define PII pair<ll,ll>
ll read(){ll c = getchar(),Nig = 1,x = 0;while(!isdigit(c) && c!='-')c = getchar();if(c == '-')Nig = -1,c = getchar();while(isdigit(c))x = ((x<<1) + (x<<3)) + (c^'0'),c = getchar();return Nig*x;}
#define read read()
/** keep hungry and keep calm! **/

struct mat{
    ll m[105][105];
};

int m;
const mat operator *(mat &a,mat &b){
    mat ans;
    for(int i=1;i<=m;i++){
        for(int j=1;j<=m;j++){
            ans.m[i][j]=0;
            for(int k=1;k<=m;k++){
                ans.m[i][j]+=(a.m[i][k]*b.m[k][j])%mod;
                if(ans.m[i][j]>=mod) ans.m[i][j]-=mod;
            }
        }
    }
    return ans;
}

ll qpow(mat a,ll b){
    mat ans;
    for(int i=1;i<=m;i++){
        for(int j=1;j<=m;j++){
            ans.m[i][j]=(i==j);
        }
    }

    while(b){
        if(b&1) ans=ans*a;
        a=(a*a);b>>=1;
    }

    ll res=ans.m[1][1];
    for(int i=1;i<=m;i++){
        res+=ans.m[1][i];
        if(res>=mod) res-=mod;
    }
    return res;
}

int Sheryang(){

    ll n=read;
    m=read;

    if(n<m){
        return printf("1"),0;
    }else if(n==m){
        return printf("2"),0;
    }

    mat a;
    memset(a.m,0,sizeof(a.m));
    a.m[1][1]=1;a.m[1][m]=1;
    for(int i=2;i<=m;i++){
        a.m[i][i-1]=1;
    }

    printf("%lld\n",qpow(a,n-m));
    return 0;
}

#include<bits/stdc++.h>
#define int long long
using namespace std;
#define For(i,a,b) for ( int i=(a);i<=(b);i++ )
#define Dow(i,a,b) for ( int i=(a);i>=(b);i-- )
const int N=105,Mo=1e9+7;
inline int read()
{
	int x=0,f=0; char ch=getchar();
	while(!isdigit(ch)) f|=(ch=='-')?1:0,ch=getchar();
	while(isdigit(ch)) x=x*10ll+(ch^48),ch=getchar();
	return (f)?-1ll*x:x;
}
int n,m;
struct Node
{
	int a[N][N];
	Node(){memset(a,0,sizeof(a));}
	inline Node friend operator * (const Node &s,const Node &t)
	{
		Node ans;
		For(i,0,m-1) For(j,0,m-1) For(k,0,m-1)
		ans.a[i][j]=(ans.a[i][j]+s.a[i][k]*t.a[k][j]%Mo+Mo)%Mo;
		return ans;
	}
};
Node pre,extend;
inline Node ksm(Node x,int y)
{
	Node ans;
	For(i,0,m-1) For(j,0,m-1) ans.a[i][j]=(i==j);
	while(y)
	{
		if(y&1ll) ans=ans*x;
		x=x*x;
		y>>=1ll;
	}
	return ans;
}
signed main()
{
	n=read(),m=read();
	if(n<m) return printf("1\n"),0;
	For(i,0,m-1) pre.a[0][i]=1;
	extend.a[0][0]=1;
	For(i,0,m-1) if(i>=1) extend.a[i-1][i]=1;
	extend.a[m-1][0]=1;
	extend=ksm(extend,n-m+1);
	pre=pre*extend;
	printf("%lld\n",pre.a[0][0]);
	return 0;
}

#include<bits/stdc++.h>
#define int long long
#define ll long long
#define pb emplace_back
#define mp make_pair
#define tci(v,i) for(auto i=v.begin();i!=v.end();i++)
#define all(v) v.begin(),v.end()
#define rep(i,start,lim) for(long long (i)=(start);i<(lim);i++)
#define revrep(i,n) for(long long i=n-1;i>=0;i--)
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define osit ostream_iterator<int> output (cout," ")
#define pv(x) copy(all(x),output)
#define pa(a) rep(i,0,sizeof(a)/sizeof(a[0]))cout<<a[i]<<" "
#define endl '\n'
#define f first
#define s second
#define PI 3.141592653589793
#define test int t;cin>>t; while(t--)
#define set0(x) memset(x,0,sizeof(x))
#define set1(x) memset(x,1,sizeof(x))
#define getarr(arr,n) int arr[n];rep(i,0,n)cin>>a[i]
#define getvec(vec,n) vi vec;int x;rep(i,0,n){cin>>x;vec.pb(x);}
#define dg(x) cout<<#x<<':'<<x<<endl;
#define dg2(x,y) cout<<#x<<':'<<x<<' '<<#y<<':'<<y<<endl;
#define dg3(x,y,z) cout<<#x<<':'<<x<<' '<<#y<<':'<<y<<' '<<#z<<':'<<z<<endl;
#define dg4(x,y,z,zz) cout<<#x<<':'<<x<<' '<<#y<<':'<<y<<' '<<#z<<':'<<z<<' '<<#zz<<':'<<zz<<endl;
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;
template<typename T> T gcd(T a,T b){if(a==0) return b; return gcd(b%a,a);}
vi b_v;void bin(unsigned int n) { if (n > 1) bin(n>>1); b_v.pb(n & 1); }
int isPowerof2(int x) { return (x && !(x & x-1)); }

const int mod=1e9+7;
int n,m;

void mult(vvi& A, vvi& B){
    int m = A.size();
    vvi C(m, vi(m, 0));
    for(int i=0; i<m; i++){
        for(int j=0; j<m; j++){
            for(int k=0; k<m; k++){
                C[i][j] += A[i][k] * B[k][j];
                C[i][j] %= mod;
            }
        }
    }
    A = C;
}

int32_t main(){
    boost;osit;
    cin>>n>>m;
    vvi A(m,vi(m,0));
    vvi X(m,vi(m,0));
    A[0][0]=1;
    A[0][m-1]=1;
    rep(i,1,m)A[i][i-1]=1;
    X[0][0]=1;
    while(n>0){
        if(n&1){
            n--;
            mult(X,A);
        }else{
            n/=2;
            mult(A,A);
        }
    }
    cout<<X[0][0];
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define pb push_back
typedef long long ll;
#define SZ(x) ((ll)(x).size())
typedef vector<ll> VI;
typedef pair<ll,ll> PII;
const ll mod=(ll)1e9 + 7;
ll powmod(ll a,ll b) {
    ll res=1;
    a%=mod;
    assert(b>=0);
    for(; b; b>>=1) {
        if(b&1)res=res*a%mod;
        a=a*a%mod;
    }
    return res;
}
ll _,n;
namespace linear_seq {
    const ll N=10010;
    ll res[N],base[N],_c[N],_md[N];

    vector<ll> Md;
    void mul(ll *a,ll *b,ll k) {
        rep(i,0,k+k) _c[i]=0;
        rep(i,0,k) if (a[i]) rep(j,0,k) _c[i+j]=(_c[i+j]+a[i]*b[j])%mod;
        for (ll i=k+k-1; i>=k; i--) if (_c[i])
                rep(j,0,SZ(Md)) _c[i-k+Md[j]]=(_c[i-k+Md[j]]-_c[i]*_md[Md[j]])%mod;
        rep(i,0,k) a[i]=_c[i];
    }
    ll solve(ll n,VI a,VI b) { // a 系数 b 初值 b[n+1]=a[0]*b[n]+...
        ll ans=0,pnt=0;
        ll k=SZ(a);
        assert(SZ(a)==SZ(b));
        rep(i,0,k) _md[k-1-i]=-a[i];
        _md[k]=1;
        Md.clear();
        rep(i,0,k) if (_md[i]!=0) Md.push_back(i);
        rep(i,0,k) res[i]=base[i]=0;
        res[0]=1;
        while ((1ll<<pnt)<=n) pnt++;
        for (ll p=pnt; p>=0; p--) {
            mul(res,res,k);
            if ((n>>p)&1) {
                for (ll i=k-1; i>=0; i--) res[i+1]=res[i];
                res[0]=0;
                rep(j,0,SZ(Md)) res[Md[j]]=(res[Md[j]]-res[k]*_md[Md[j]])%mod;
            }
        }
        rep(i,0,k) ans=(ans+res[i]*b[i])%mod;
        if (ans<0) ans+=mod;
        return ans;
    }
    VI BM(VI s) {
        VI C(1,1),B(1,1);
        ll L=0,m=1,b=1;
        rep(n,0,SZ(s)) {
            ll d=0;
            rep(i,0,L+1) d=(d+(ll)C[i]*s[n-i])%mod;
            if (d==0) ++m;
            else if (2*L<=n) {
                VI T=C;
                ll c=mod-d*powmod(b,mod-2)%mod;
                while (SZ(C)<SZ(B)+m) C.pb(0);
                rep(i,0,SZ(B)) C[i+m]=(C[i+m]+c*B[i])%mod;
                L=n+1-L;
                B=T;
                b=d;
                m=1;
            } else {
                ll c=mod-d*powmod(b,mod-2)%mod;
                while (SZ(C)<SZ(B)+m) C.pb(0);
                rep(i,0,SZ(B)) C[i+m]=(C[i+m]+c*B[i])%mod;
                ++m;
            }
        }
        return C;
    }
    ll gao(VI a,ll n) {
        VI c=BM(a);
        c.erase(c.begin());
        rep(i,0,SZ(c)) c[i]=(mod-c[i])%mod;
        return solve(n,c,VI(a.begin(),a.begin()+SZ(c)));
    }
};

ll m, f[300];

int main() {
   ios::sync_with_stdio(false);
   cin.tie(0);
   cin >> n >> m;
   for (int i = 0; i < m; ++i) f[i] = 1;
   for (int i = m; i <= 200; ++i) {
        f[i] = (f[i - 1] + f[i - m]) % mod;
   }
   VI v;
   for (int i = 1; i <= 200; ++i) {
        v.push_back(f[i]);
   }
   cout << linear_seq::gao(v,n-1)%mod << '\n';
   return 0;
}

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using vll = vector<ll>;
using vii = vector<int>;
using pii = pair<int, int>;
using vvl = vector<vll>;

const ll MOD = 1e9 + 7;

struct matrix {
    vvl mat;

    matrix(int n, int m, int e = 0) : mat(vvl(n, vll(m, e))) {}
    matrix(int n, bool eye = false) : matrix(n, n) {
        if (eye) {
            for (int i = 0; i < n; i++) {
                mat[i][i] = 1;
            }
        }
    }
    // matrix(vvl mat) : mat(mat) {}

    int rows() const { return mat.size(); }
    int cols() const { return mat[0].size(); }

    void operator*=(matrix& rhs) {
        const int n = rows(), m = rhs.cols();
        vvl prod(n, vll(m, 0));
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                for (int k = 0; k < rhs.rows(); k++) {
                    (prod[i][j] += mat[i][k] * rhs[k][j]) %= MOD;
                }
            }
        }
        swap(mat, prod);
    }

    friend matrix operator*(matrix lhs, matrix rhs) {
        lhs *= rhs;
        return lhs;
    }

    friend matrix operator^(matrix& a, ll n) {
        matrix res(a.cols(), true);
        for (; n; a *= a, n >>= 1)
            if (n & 1)
                res *= a;
        return res;
    }

    vll& operator[](int i) { return mat[i]; }

    friend ostream& operator<<(ostream& out, matrix m) {
        for (auto v : m.mat) {
            for (auto e : v)
                out << e << " ";
            out << endl;
        }
        return out;
    }
};

int main() {
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);

    ll n = 576460752303423487;
    // ll n = 4;

    cin >> n;

    int m = 100;
    cin >> m;

    matrix mat(m), f(m, 1);

    for (int i = 0; i < m; i++) {
        if (i < m - 1)
            mat[i + 1][i] = 1;
    }
    mat[0][0] = mat[0][m - 1] = 1;
    f[0][0] = 1;

    // cerr << mat << '\n';
    // cerr << f << '\n';

    auto res = (mat ^ n) * f;

    cout << res[0][0] << '\n';
}

#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define y1 yy1

using namespace std;

const int N=200005;
const ll mod=1000000007;

ll n,k,ans;

ll m[105][105];
ll mat[105][105];
ll one[105][105];
ll res[105][105];

void mult(ll a[105][105],ll b[105][105])
{
          ll res[105][105];
          for(int i=0;i<k;i++)
                    for(int j=0;j<k;j++)
                              res[i][j]=0;

          for(int i=0;i<k;i++)
                    for(int j=0;j<k;j++)
                              for(int p=0;p<k;p++)
                                        res[i][j]=(res[i][j]+a[i][p]*b[p][j])%mod;

          for(int i=0;i<k;i++)
                    for(int j=0;j<k;j++)
                              a[i][j]=res[i][j];
}

void bpow(ll x)
{
          while(x)
          {
                    if(x&1)
                              mult(mat,m);
                    mult(m,m);
                    x>>=1;
          }
}

int main()
{
          ios_base::sync_with_stdio(0);
          //freopen("INPUT.txt","r",stdin);
          cin>>n>>k;
          if(k>n)
          {
                    cout<<1;
                    return 0;
          }
          m[0][0]=1;
          m[k-1][0]=1;
          for(int i=1;i<k;i++)
                    m[i-1][i]=1;

          for(int i=0;i<k;i++)
                              mat[i][i]=1;

         bpow(n-k+1);

          for(int i=0;i<k;i++)
                    ans=(mat[0][i]+ans)%mod;
          cout<<ans;

}

#include <bits/stdc++.h>

#define taskname ""
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define for0(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex <ld> cd;
typedef vector <cd> vcd;
typedef vector <int> vi;

template<class T> bool uin(T &a, T b)
{
    return a > b ? (a = b, true) : false;
}
template<class T> bool uax(T &a, T b)
{
    return a < b ? (a = b, true) : false;
}

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

const int maxN = 1e5;
const ll mod = 1e9 + 7;

struct Matrix
{
    int n, m;
    vector <vector <ll>> s;
    Matrix() : n(0), m(0) {}
    Matrix(vector <vector <ll>>& a)
    {
        s = a;
        n = s.size();
        if (n > 0)
        {
            m = s[0].size();
        }
    }
    Matrix(int n, int m) : n(n), m(m)
    {
        s = vector <vector <ll>>(n, vector <ll>(m));
    }
    vector <ll>& operator[](int i)
    {
        return s[i];
    }
    Matrix operator*(Matrix a)
    {
        int p = a.m;
        vector <vector <ll>>& tmp = a.s, t(p, vector <ll>(m));
        //Transpose
        for0(i, m)
        {
            for0(j, p)
            {
                t[j][i] = tmp[i][j];
            }
        }
        Matrix r(n, p);
        for0(i, n)
        {
            for0(j, p)
            {
                ll sum = 0;
                for0(k, m)
                {
                    sum += s[i][k] * t[j][k] % mod;
                }
                r[i][j] = sum % mod;
            }
        }
        return r;
    }
};

Matrix power(Matrix a, ll b)
{
    //square matrix
    int n = a.n;
    Matrix r(n, n);
    for0(i, n)
    {
        r[i][i] = 1;
    }
    while (b)
    {
        if (b & 1)
        {
            r = r * a;
        }
        b >>= 1;
        a = a * a;
    }
    return r;
}

ll n;
int m;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> m;
    if (n < m)
    {
        cout << 1;
        return 0;
    }
    Matrix ans(1, m), b(m, m);
    for0(j, m)
    {
        ans[0][j] = 1;
    }
    for1(i, m - 1)
    {
        b[i][i - 1] = 1;
    }
    b[0][m - 1] = b[m - 1][m - 1] = 1;
    ans = ans * power(b, n - m + 1);
    cout << ans[0][m - 1];
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
ll qpow( ll x , ll y)
{
    ll ans = 1;
    x %= mod;
    while( y ){
        if( y & 1 )
            ans = ans * x % mod;
        x = x * x % mod;
        y >>= 1;
    }
    return ans;
}
typedef vector<int> VI;
namespace linear_seq{
    const int n = 10010;
    ll res[n], base[n], c[n], md[n];
    vector < int > Md;
    void mul( ll *a, ll *b, int k){
        for ( int i = 0; i < k + k; i++){
            c[i] = 0;
        }
        for ( int i = 0; i < k; i++){
            if ( a[i] ){
                for (int j = 0; j < k; j++){
                    c[ i + j ]=( c[ i + j ] + a[i] * b[j] ) % mod;
                }
            }
        }
        for (int i = k + k - 1; i >= k; i--){
            if ( c[i] ){
                for (int j = 0; j < (int)Md.size(); j++){
                    c[ i - k + Md[j] ] = ( c[ i - k + Md[j] ] - c[i] * md[ Md[j] ]) % mod;
                }
            }
        }
        for (int i = 0; i < k; i++){
            a[i] = c[i];
        }
    }

    ll solve( ll n, VI a, VI b){
        ll ans = 0, pnt = 0;
        int k = (int)a.size();
        assert( (int)a.size() == (int)b.size() );
        for (int i = 0; i < k; i++){
            md[ k - 1 - i] = - a[i];
        }
        md[k] = 1;
        Md.clear();
        for ( int i = 0; i < k; i++){
            if ( md[i] != 0){
                Md.push_back(i);
            }
        }
        for ( int i = 0; i < k; i++){
            res[i] = base[i] = 0;
        }
        res[0] = 1;
        while ( ( 1ll << pnt ) <= n ){
            pnt++;
        }
        for (int p = pnt; p >= 0; p--){
            mul( res, res, k);
            if ( ( n>>p ) & 1){
                for (int i = k - 1; i >= 0; i--){
                    res[ i + 1 ]=res[i];
                }
                res[0] = 0;
                for (int j = 0; j< (int) Md.size(); j++){
                    res[ Md[j] ]=( res[ Md[j] ]- res[k] * md[ Md[j] ] ) % mod;
                }
            }
        }
        for (int i = 0; i < k; i++){
            ans=( ( ans + res[i] * b[i] ) % mod + mod ) % mod;
        }
        return ans;
    }
    VI BM( VI s){
        VI C( 1 , 1 ), B( 1 , 1 );
        int L = 0, m = 1, b = 1;
        for ( int n = 0; n < (int)s.size(); n++){
            ll d = 0;
            for (int i = 0; i < L + 1; i++){
                d=( d + (ll)C[i] * s[ n - i ] ) % mod;
            }
            if ( d == 0 ){
                m++;
            }
            else if ( 2 * L <= n ){
                VI T = C;
                ll c = mod - d*qpow( b, mod - 2 ) % mod;
                while ( (int)C.size() < (int)B.size() + m){
                    C.push_back(0);
                }
                for ( int i = 0; i < (int)B.size(); i++){
                    C[ i + m ] = ( C[ i + m ] + c * B[ i ] ) % mod;
                }
                L = n + 1 - L;
                B = T;
                b = d;
                m = 1;
            }
            else {
                ll c = mod - d * qpow( b , mod - 2 ) % mod;
                while ( (int)C.size() < (int)B.size() + m ){
                    C.push_back(0);
                }
                for (int i = 0; i < (int)B.size(); i++){
                    C[ i + m ]= ( C[ i + m ] + c * B[ i ] ) % mod;
                }
                m++;
            }
        }
        return C;
    }
    ll gao( VI a, ll n){
        VI c = BM( a );
        c.erase( c.begin() );
        for (int i = 0; i < (int)c.size(); i++){
            c[i]= ( mod - c[i] )%mod;
        }
        return solve( n, c, VI( a.begin(), a.begin() + (int)c.size() ) );
    }
};
ll f[300];
int main()
{
    int m;
    ll n;
    scanf("%lld%d",&n,&m);
    VI a;
    for(int i=1;i<=m;i++){
        f[i]=1;
    }
    for(int i=m;i<=200;i++){
        f[i]=(f[i-1]+f[i-m])%mod;
    }
    for(int i=1;i<=200;i++){
        a.push_back(f[i]);
    }
    n++;
    ll ans=linear_seq::gao(a,n-1);
    printf("%lld\n",ans%mod);
    return 0;
}

//Coded by tzc_wk
/*
数据不清空，爆零两行泪。
多测不读完，爆零两行泪。
边界不特判，爆零两行泪。
贪心不证明，爆零两行泪。
D P 顺序错，爆零两行泪。
大小少等号，爆零两行泪。
变量不统一，爆零两行泪。
越界不判断，爆零两行泪。
调试不注释，爆零两行泪。
溢出不 l l，爆零两行泪。
*/
#include <bits/stdc++.h>
using namespace std;
#define fi			first
#define se			second
#define fz(i,a,b)	for(int i=a;i<=b;i++)
#define fd(i,a,b)	for(int i=a;i>=b;i--)
#define foreach(it,v) for(__typeof(v.begin()) it=v.begin();it!=v.end();it++)
#define all(a)		a.begin(),a.end()
#define giveup(...) return printf(__VA_ARGS__),0;
#define fill0(a)	memset(a,0,sizeof(a))
#define fill1(a)	memset(a,-1,sizeof(a))
#define fillbig(a)	memset(a,0x3f,sizeof(a))
#define fillsmall(a) memset(a,0xcf,sizeof(a))
#define mask(a)		(1ll<<(a))
#define maskx(a,x)	((a)<<(x))
#define _bit(a,x)	(((a)>>(x))&1)
#define _sz(a)		((int)(a).size())
#define filei(a)	freopen(a,"r",stdin);
#define fileo(a)	freopen(a,"w",stdout);
#define fileio(a) 	freopen(a".in","r",stdin);freopen(a".out","w",stdout)
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define put(x)		putchar(x)
#define eoln        put('\n')
#define space		put(' ')
#define y1			y_chenxiaoyan_1
#define y0			y_chenxiaoyan_0
#define int long long
typedef pair<int,int> pii;
inline int read(){
	int x=0,neg=1;char c=getchar();
	while(!isdigit(c)){
		if(c=='-')	neg=-1;
		c=getchar();
	}
	while(isdigit(c))	x=x*10+c-'0',c=getchar();
	return x*neg;
}
inline void print(int x){
	if(x<0){
		putchar('-');
		print(abs(x));
		return;
	}
	if(x<=9)	putchar(x+'0');
	else{
		print(x/10);
		putchar(x%10+'0');
	}
}
inline int qpow(int x,int e,int _MOD){
	int ans=1;
	while(e){
		if(e&1)	ans=ans*x%_MOD;
		x=x*x%_MOD;
		e>>=1;
	}
	return ans;
}
const int MOD=1e9+7;
int n=read(),m=read();
struct matrix{
	int a[105][105];
	matrix(){
		fill0(a);
	}
	inline matrix operator *(matrix b){
		matrix ans;
		fz(i,1,m){
			fz(j,1,m){
				fz(k,1,m){
					ans.a[i][j]=(ans.a[i][j]+a[i][k]*b.a[k][j]%MOD)%MOD;
				}
			}
		}
		return ans;
	}
};
signed main(){
	matrix t,k;
	fz(i,1,m-1)	t.a[i+1][i]=1;
	t.a[1][m]=t.a[m][m]=1;
	fz(i,1,m)	k.a[1][i]=1;
	matrix ans;
	fz(i,1,m)	ans.a[i][i]=1;
	while(n){
		if(n%2)	ans=ans*t;
		t=t*t;
		n>>=1;
	}
//	fz(i,1,m){
//		fz(j,1,m)	cout<<ans.a[i][j]<<" ";
//		puts("");
//	}
	k=k*ans;
	cout<<k.a[1][1]<<endl;
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define int long long

const int base = 311, mod = 1e9 + 7, N = 1e6 + 11, inf = INT_MAX;

int n, m;

int multi(int a, int n)
{
	int res = 0;
	while(n)
	{
		if(n&1)
		{
			res = (res + a) % mod;
		}
		a = (a + a) % mod;
		n >>= 1;
	}
	return res;
}

struct matrix
{
	vector<vector<int>>a;
	matrix (int n, int m)
	{
		a.assign(n,vector<int>(m));
 	}
	matrix operator * (const matrix &b) const
	{
		int m = a.size(), n = b.a.size(), p = b.a[0].size();
		matrix c(m, p);
		for(int i = 0; i < m;i++)
		{
			for(int k = 0; k < n; k++)
			{
				for(int j = 0; j < p; j++)
				{
					c.a[i][j] = (c.a[i][j] + (a[i][k] * b.a[k][j]) % mod) % mod;
				}
			}
		}
		return c;
	}
};

matrix pow_matrix(matrix a, int k)
{
	int n=a.a.size();
	matrix res(n,n);
	for(int i=0;i<n;i++)
	{
		res.a[i][i]=1;
	}
	while(k)
	{
		if(k & 1)
		{
			res = res * a;
		}
		a = a * a;
		k >>= 1;
	}
	return res;
}

signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> n >> m;
	matrix ans(m, m);
	for (int i = 1; i < m; i++) {
		ans.a[i - 1][i] = 1;
	}
    	ans.a[m - 1][0] = ans.a[m - 1][m - 1] = 1;
    	ans = pow_matrix(ans, n);
    	cout << ans.a[m - 1][m - 1];
}

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;

#define fill(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define sz(x) (int)x.size()
#define F first
#define S second
#define FOR(i,a,b) for(int i = a; i<=b; ++i)
#define NFOR(i,a,b) for(int i = a; i>=b; --i)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
const ll INF = 1e18;
const ll mod = 1e9+7;
const int N = 1e5+10;

const int SZ=110;
int actualSize;

ll res[SZ][SZ];
struct matrix
{
	ll arr[SZ][SZ];

	void makezeros()
	{
		for(int i=0;i<actualSize;i++)
		for(int j=0;j<actualSize;j++)
		arr[i][j]=0;
	}

	void base()
	{
		makezeros();
		arr[0][0] = 1;
		arr[0][actualSize-1] = 1;
		for(int i=1;i<actualSize;i++)
		arr[i][i-1] = 1;
	}

	void makeiden()
	{
		makezeros();
		for(int i=0;i<actualSize;i++)
		{
			arr[i][i] = 1;
		}
	}

	ll answer(){
		ll ans = 0;
		for(int i=0;i<actualSize;i++)
		ans+=arr[0][i];

		ans%=mod;
		if(ans<0)
		ans+=mod;

		return ans;
	}

	void add(const matrix &o)
	{
		for(int i=0;i<actualSize;i++)
		{
			for(int j=0;j<actualSize;j++)
			{
				arr[i][j] = arr[i][j] + o.arr[i][j];
				if(arr[i][j]>=mod)
				arr[i][j]-=mod;
			}
		}
	}

	void mult(const matrix &o)
	{
		for(int i=0;i<actualSize;i++)
		{
			for(int j=0;j<actualSize;j++)
			{
				res[i][j] = 0;
				for(int k=0;k<actualSize;k++)
				{
					res[i][j] += arr[i][k]*o.arr[k][j];
					res[i][j]%=mod;
				}
			}
		}

		for(int i=0;i<actualSize;i++)
		for(int j=0;j<actualSize;j++)
		arr[i][j]=res[i][j];
	}

};

matrix power(matrix a, ll b)
{
	matrix ret;
	ret.makeiden();

	if(b<=0)
	return ret;

	while(b)
	{
		if(b & 1)
		{
			ret.mult(a);
		}
		a.mult(a);
		b >>= 1;
	}
	return ret;
}

int main(){
  fast;

  ll n;
  cin>>n>>actualSize;

  matrix mat;

  mat.base();
  mat = power(mat,n-actualSize+1);
  cout<<mat.answer()<<endl;

  return 0;
}

#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
//using namespace __gnu_pbds;
//typedef tree<
//        pair<long long, int>, // change type
//        null_type,
//        less<pair<long long, int> >, // change type
//        rb_tree_tag,
//        tree_order_statistics_node_update>
//        ordered_set;

typedef long long ll;
#define rep(i, start, end) for(int i = start; i < end; ++i)
#define sz(x) (int)(x).size()
#define pb push_back
#define row first
#define col second
#define all(x) x.begin(), x.end()
#define clr(d, v) memset(d, v, sizeof(d))
#define pii pair<int, int>
const double PI = 3.14159265358979323846;
const double eps = (1e-4);
int dcmp(long double x, long double y)
{
    if (abs(x - y) < eps)
        return 0;
    if (x > y)
        return 1;
    return -1;
}

const unsigned long long mod = 1000000007;
struct Matrix {
    long long v[200][200];
    int row, col; // row x col
    Matrix(int n = 0, int m = 0, long long a = 0) {
        memset(v, 0, sizeof(v));
        row = n, col = m;
        for(int i = 0; i < row && i < col; i++)
            v[i][i] = a;
    }
    Matrix operator*(const Matrix& x) const {
        Matrix ret(row, x.col);
        for(int i = 0; i < row; i++) {
            for(int k = 0; k < col; k++) {
                if (v[i][k])
                    for(int j = 0; j < x.col; j++) {
                        ret.v[i][j] += v[i][k] * x.v[k][j],
                                ret.v[i][j] %= mod;
                    }
            }
        }
        return ret;
    }
    Matrix operator^(const long long& n) const {
        Matrix ret(row, col, 1), x = *this;
        long long y = n;
        while(y) {
            if(y&1)	ret = ret * x;
            y = y>>1, x = x * x;
        }
        return ret;
    }
    long long& operator() (int i, int j){
        return v[i][j];
    }
};

ll n;
int m;
Matrix transform1;
Matrix transform2;
Matrix base;
Matrix transform3, ret;
bool valid(int i)
{
    return i >= 0 && i < m + 1;
}

void f(Matrix &m, int i, int j)
{
    if (valid(i) && valid(j))
        m(i, j) = 1;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
//    freopen("facebook.txt", "w", stdout);
#endif
    cin >> n >> m;
    transform1.row = transform1.col = transform2.row = transform2.col = m + 1;
    base.row = m + 1;
    base.col = 1;
    base(0,0) = 1;
    for (int i = 0; i < m + 1; ++i)
    {
        f(transform2, i, i + 1);
        f(transform1, i, i);
    }
    f(transform1, 1, 0);
    f(transform1, m, 0);
    transform3 = transform2 * transform1;
    transform3 = transform3^n;
    ret = transform3 * base;
    cout << ret(0,0);

    return 0;
}

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;

#define fill(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define sz(x) (int)x.size()
#define F first
#define S second
#define FOR(i,a,b) for(int i = a; i<=b; ++i)
#define NFOR(i,a,b) for(int i = a; i>=b; --i)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
const ll INF = 1e18;
const ll mod = 1e9+7;
const int N = 1e5+10;

const int SZ=110;
int actualSize;

ll res[SZ][SZ];
struct matrix
{
	ll arr[SZ][SZ];

	void makezeros()
	{
		for(int i=0;i<actualSize;i++)
		for(int j=0;j<actualSize;j++)
		arr[i][j]=0;
	}

	void base()
	{
		makezeros();
		arr[0][0] = 1;
		arr[0][actualSize-1] = 1;
		for(int i=1;i<actualSize;i++)
		arr[i][i-1] = 1;
	}

	void makeiden()
	{
		makezeros();
		for(int i=0;i<actualSize;i++)
		{
			arr[i][i] = 1;
		}
	}

	ll answer(){
		ll ans = 0;
		for(int i=0;i<actualSize;i++)
		ans+=arr[0][i];

		ans%=mod;
		if(ans<0)
		ans+=mod;

		return ans;
	}

	void add(const matrix &o)
	{
		for(int i=0;i<actualSize;i++)
		{
			for(int j=0;j<actualSize;j++)
			{
				arr[i][j] = arr[i][j] + o.arr[i][j];
				if(arr[i][j]>=mod)
				arr[i][j]-=mod;
			}
		}
	}

	void mult(const matrix &o)
	{
		for(int i=0;i<actualSize;i++)
		{
			for(int j=0;j<actualSize;j++)
			{
				res[i][j] = 0;
				for(int k=0;k<actualSize;k++)
				{
					res[i][j] += arr[i][k]*o.arr[k][j];
					res[i][j]%=mod;
				}
			}
		}

		for(int i=0;i<actualSize;i++)
		for(int j=0;j<actualSize;j++)
		arr[i][j]=res[i][j];
	}

};

matrix power(matrix& a, ll b)
{
	matrix ret;
	ret.makeiden();

	if(b<=0)
	return ret;

	while(b)
	{
		if(b & 1)
		{
			ret.mult(a);
		}
		a.mult(a);
		b >>= 1;
	}
	return ret;
}

int main(){
  fast;

  ll n;
  cin>>n>>actualSize;

  matrix mat;

  mat.base();
  mat = power(mat,n-actualSize+1);
  cout<<mat.answer()<<endl;

  return 0;
}

#include <bits/stdc++.h>
#define ll long long
#define MOD 1000000007
#define CAP 1000000
#define inf 100000000000000000LL
#define pii pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define endl '\n'
#define sz(v) v.size()
#define all(v)    v.begin(),v.end()
#define rep(i,n)    for(ll i=0;i<n;++i)
#define fast  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//#define int ll
using namespace std;
ll n,m;
map<ll,ll> map1;
ll f(ll x){
    if(map1[x]) return map1[x];
    if(x<0) return 0;
    if(x<m) return 1;
    ll xx=x/2;
    ll ans=f(xx)*f(x-xx);
    ans%=MOD;
    for(int i=1;i<m;i++){
        ans+=f(xx-i)*f(x-xx-m+i);
        ans%=MOD;
    }
    map1[x]=ans;
    return ans;
}
signed main(){
    cin>>n>>m;
    ll ans=f(n);
    cout<<ans;
}

#include <algorithm>
#include <iostream>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <cstdint>
#include <cstdio>
#include <vector>
#include <string>
#include <deque>
#include <cmath>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include <cstring>
#include <assert.h>
#include <chrono>
#include <random>
#include <functional>
#include <bitset>
#include <iterator>

using namespace std;

const int MAXN = 1.1e6;
const int MOD = (int)(1e9) + 7;

typedef vector<vector<int> > matrix;

matrix matmul(int M, const matrix& A, const matrix& B) {
  matrix gu(M, vector<int>(M));
  for (int i = 0; i < M; i++) {
    for (int j = 0; j < M; j++) {
      for (int k = 0; k < M; k++) {
	gu[i][j] += (1LL * A[i][k] * B[k][j]) % MOD;
	gu[i][j] %= MOD;
      }
    }
  }
  return gu;
}

matrix matpow(int M, const matrix& A, long long k) {
  if (k == 1) return A;
  matrix hlf = matpow(M, A, k / 2);
  matrix ans = matmul(M, hlf, hlf);
  if (k % 2) ans = matmul(M, ans, A);
  return ans;
}

int main() {
  long long N;
  int M;
  cin >> N >> M;
  if (N <= M) {
    cout << (N == M ? 2 : 1) << '\n';
    return 0;
  }
  matrix transition(M, vector<int>(M));
  // first row, compute next state:
  transition[0][0] = 1;
  transition[0][M - 1] = 1;
  // rest of the rows: (M - 1) x (M - 1) identity
  // matrix to preserve state of first M - 1 variables
  for (int i = 0; i < M - 1; i++) {
    transition[i + 1][i] = 1;
  }
  matrix full_state = matpow(M, transition, N - M);
  int ans = 0;
  for (int i = 0; i < M; i++) {
    if (i == 0) ans += (2LL * full_state[0][i]) % MOD;
    else ans += full_state[0][i];
    ans %= MOD;
  }
  cout << ans << '\n';
  return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
ll n,m;
struct mat
{
    ll a[105][105];
};
mat mat_mul(mat x,mat y)
{
    mat res;
    memset(res.a,0,sizeof(res.a));
    for(int i=0;i<m;i++)
        for(int j=0;j<m;j++)
        for(int k=0;k<m;k++)
        res.a[i][j]=(res.a[i][j]+x.a[i][k]*y.a[k][j])%MOD;
    return res;
}
void mat_pow(ll n)
{
    mat c,res;
    c.a[0][0]=c.a[0][m-1]=1;
    for(int i=1;i<m;i++)
    {
        c.a[i][i-1]=1;
    }

    memset(res.a,0,sizeof(res.a));
    for(int i=0;i<m;i++) res.a[i][i]=1;
    n--;
    while(n)
    {
        if(n&1) res=mat_mul(res,c);
        c=mat_mul(c,c);
        n=n>>1;
    }
    c=res;
    ll ans=c.a[m-1][0]*2%MOD;
    for(int j=1;j<m;j++)ans=(ans+c.a[m-1][j])%MOD;
    cout<<ans<<endl;
}
int main()
{
    cin>>n>>m;
        mat_pow(n);
    return 0;
}

#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e17;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define RFOR(i, a, b) for(ll i = (a); i > b; i--)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define RREP(i, n) for(ll i = n-1; i > -1; i--)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define epb emplace_back

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}

const ll mod = 1e9+7;

struct Matrix {
    vvl val;
    Matrix(ll n, ll m, ll x = 0) : val(n, vl(m, x)) {}
    void init(ll n, ll m, ll x = 0) {val.assign(n, vl(m, x));}
    ll size() const {return val.size();}
    inline vector<ll>& operator [] (ll i) {return val[i];}
};

Matrix operator * (Matrix A, Matrix B) {
    ll mat_size = A.size();
    Matrix R(mat_size, mat_size);
    REP(i, mat_size) REP(j, mat_size){
        A[i][j] %= mod; B[i][j] %= mod;
    }
    REP(i, mat_size) REP(j, mat_size) REP(k, mat_size){
        R[i][j] += A[i][k] * B[k][j];
        R[i][j] %= mod;
    }
    return R;
}

Matrix pow(Matrix A, ll n) {
    Matrix R(A.size(), A.size());
    REP(i, A.size()) R[i][i] = 1;
    while (n > 0) {
        if (n & 1) R = R * A;
        A = A * A;
        n >>= 1;
    }
    return R;
}

ll N, M;

void prepare(Matrix& mat){
    REP(i, M) REP(j, M){
        if(i == 0){
            if(j == 0 || j == M-1) mat[i][j] = 1;
        }
        else if(i == j+1){
            mat[i][j] = 1;
        }
    }
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> N >> M;
    auto mat = Matrix(M, M);
    prepare(mat);
    auto matN = pow(mat, N-(M-1));

    ll ans = 0;
    REP(i, M) ans += matN[0][i];
    cout << ans%mod << endl;
    return 0;

}

#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
#define f(i,n) for(int i=0;i<n;i++)
typedef long long ll;

void matrixmult(vector<vector<ll> > &a,vector<vector<ll> > &b)
{

  ll x,y,z;
  x=a[0].size();
  y=a.size();
  z=b.size();

  vector<ll> t (z,0);
  vector< vector<ll> > c(x,t);

  f(i,x) f(j,z) f(k,y) c[i][j]=(c[i][j]+(a[i][k]*b[k][j])%M) % M;

  f(i,x) f(j,z) b[i][j]=c[i][j];

}

int main()
{
      ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    ll n,m;
    cin >> n >> m;

    vector<ll> row(m,0);
    vector<vector<ll>> recur(m,row);

   vector<ll> id(m,0);
   vector<vector<ll>> ident(m,id);

   f(i,m) f(j,m) if(i==j) ident[i][j]=1;

  f(i,m-1) recur[i][i+1]=1;

  recur[m-1][0]=1;
  recur[m-1][m-1]=1;

 while(n)
 {
     if(n&1) matrixmult(recur,ident);
    matrixmult(recur,recur);
    n/=2;
 }

ll ans=0;
f(i,m) ans=(ans+ident[0][i])%M;

 cout << ans;

}

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<set>
#include<vector>
#define ms(i, j) memset(i, j, sizeof i)
#define LL long long
#define db double
#define fir first
#define sec second
#define mp make_pair
using namespace std;

namespace flyinthesky {

	const LL MO = 1000000007ll;

	LL n, m;

	struct mat {
		LL a[205][205];
		mat() {ms(a, 0);}
	} tr, f;

	mat mul(mat a, mat b) {
		mat ret;
		for (LL i = 1ll; i <= m; ++i) {
			for (LL j = 1ll; j <= m; ++j) {
				for (LL k = 1ll; k <= m; ++k) {
					ret.a[i][j] = (ret.a[i][j] + a.a[i][k] * b.a[k][j] % MO) % MO;
				}
			}
		}
		//for (LL i = 1; i <= m; ++i, putchar('\n')) for (LL j = 1; j <= m; ++j) printf("%lld ", ret.a[i][j]);
		return ret;
	}
	mat ksm(mat a, LL b) {
		mat ans, bs = a;
		LL fl = 0ll;
		while (b) {
			if (b & 1ll) {
				if (fl == 0ll) fl = 1ll, ans = bs;
				else ans = mul(ans, bs);
			}
			bs = mul(bs, bs);
			b >>= 1ll;
		}
		return ans;
	}

    void clean() {
    }
    int solve() {

    	clean();
    	cin >> n >> m;

    	if (n == m) return printf("2\n"), 0;
    	if (n < m) return printf("1\n"), 0;

    	for (LL i = 1; i < m; ++i) {
    		tr.a[i][i + 1] = 1;
		}
		tr.a[m][1] = tr.a[m][m] = 1;

		for (LL i = 1; i < m; ++i) f.a[1][i] = 1;
		f.a[1][m] = 2;

		tr = ksm(tr, n - m);

		f = mul(f, tr);

		printf("%lld\n", f.a[1][m]);

        return 0;
    }
}
int main() {
	flyinthesky::solve();
    return 0;
}
//22:02  -  :34  -  20:48   -  20:48   -  20:56
//Start  -  Finish -  Static  -  Sample  -   AC
/*
*/

// BROWNIE TK

#include <bits/stdc++.h>

typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ldb;

#define pb push_back
#define popb pop_back
#define si size()
#define be begin()
#define en end()
#define all(v) v.be, v.en
#define le length()
#define mp make_pair
#define mt make_tuple
#define F first
#define S second

#define forz(i, n) for (int i = 0; i < n; i++)
#define bui(i, m, n) for (int i = m; i < n; i++)
#define rforz(i, n) for (int i = n - 1; i >= 0; i--)
#define mui(i, m, n) for (int i = n - 1; i >= m; i--)
#define deci(n) fixed << setprecision(n)
#define high(n) __builtin_popcount(n)
#define parity(n) __builtin_parity(n)
#define ctz(n) __builtin_ctz(n)
#define lb lower_bound
#define ub upper_bound
#define er equal_range
#define maxe *max_element
#define mine *min_element
#define mod 1000000007
#define mod2 998244353
#define kira ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)

#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl

using namespace std;

/*STD fucntions*/
lli power(lli x,lli y,lli p)
{
	lli res=1;
	x=x%p;
	while(y>0)
	{
		if(y&1)
			res=(res*x)%p;
		//y must be even now
		y=y>>1; //y=y/2
		x=(x*x)%p;
	}
	return res;
}
lli gcd(lli a, lli b)
{
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
lli lcm(lli a, lli b)
{ return a * b / gcd(a, b); }
lli max(lli a, lli b)
{
  if (a > b)
    return a;
  return b;
}
lli min(lli a, lli b)
{
  if (a < b)
    return a;
  return b;
}
lli bins(lli arr[], lli l, lli r, lli x)
{
  if (r >= l) {
    lli mid = l + (r - l) / 2;
    if (arr[mid] == x)
      return mid;
    if (arr[mid] > x)
      return bins(arr, l, mid - 1, x);
    return bins(arr, mid + 1, r, x);
  }
  return -1;
}
lli modi(lli a,lli m)
{
// fermat little thm where m is prime
return power(a,m-2,m);
}
/*CODE BEGINS*/
struct matrix
{
    vector <vector <lli>>m;
};
void msi(matrix &m,int a,int b)
{
    m.m.resize(a);
    forz(i,a)
       m.m[i].resize(b);
}
void minit(matrix &m,lli x)
{
    forz(i,m.m.size())
       forz(j,m.m[0].size())
           m.m[i][j]=x;
}
matrix mul(matrix m1,matrix m2)
{
    matrix m3;
    msi(m3,m1.m.size(),m2.m[0].size());
    forz(i,m3.m.size())
      {
          forz(j,m3.m[0].size())
          {    m3.m[i][j]=0;
               forz(k,m1.m[0].size())
                 m3.m[i][j]=(m3.m[i][j]+m1.m[i][k]*m2.m[k][j])%mod;
          }
      }
      return m3;
}
matrix mexp(matrix &mx,lli p)
{
   matrix res;
   msi(res,mx.m.size(),mx.m.size());
   minit(res,0);
   forz(i,mx.m.size())
      res.m[i][i]=1;
   while(p>0)
   {
     if(p&1)
       res=mul(res,mx);
     mx=mul(mx,mx);
     p=p>>1;
   }
   return res;
}
int main()
{
 kira;
 lli n;
 int m;
 cin>>n>>m;
 matrix a;
 msi(a,m,m);
 a.m[0][0]=1;
 a.m[0][m-1]=1;
 for(int i=1;i<m;i++)
 a.m[i][i-1]=1;
 a=mexp(a,n);
 cout<<a.m[0][0];
 return 0;
}

#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1 << 28;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;

struct mint {
	long long x;
	mint(long long x = 0) :x((x% mod + mod) % mod) {}
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const {
		mint res(*this);
		return res /= a;
	}
};

const int MatrixSize = 100;
using Matrix = array<array<mint, MatrixSize>, MatrixSize>;
Matrix operator * (Matrix &A, Matrix &B) {
	Matrix R = { {} };
	for (int i = 0; i < A.size(); ++i)
		for (int j = 0; j < B[0].size(); ++j)
			for (int k = 0; k < B.size(); ++k)
				R[i][j] = (R[i][j] + A[i][k] * B[k][j]) ;
	return R;
}

Matrix modpow(Matrix A, long long n) {
	Matrix R = { {} };
	for (int i = 0; i < A.size(); ++i) R[i][i] = 1;
	while (n > 0) {
		if (n & 1) R = R * A;
		A = A * A;
		n >>= 1;
	}
	return R;
}

int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/

	ll N, M; scanf("%lld %lld", &N, &M);
	if (N < M) {
		puts("1");
		return 0;
	}
	Matrix mat = { {} };
	vector<ll> ini(M, 1);
	for (ll i = 1; i < M; i++) {
		mat[i][i - 1] = 1;
	}
	mat[0][M - 1] = 1;
	mat[0][0] = 1;
	mat = modpow(mat, N - M + 1);
	mint res = 0;
	for (int i = 0; i < M; i++) (res += mat[0][i]);
	cout << res.x << endl;
	return 0;

}

#include <stdio.h>
#include <iostream>
typedef long long LL;
using namespace std;
int M = 1000000007;
int** initMatrix(int m){
    int** matrix = (int**)malloc(m*sizeof(int*));
    for(int i = 0;i<m;i++){
        matrix[i] = (int*)malloc(sizeof(int));
    }
    for(int i = 0;i<m;i++){
        for(int j = 0;j<m;j++){
            matrix[i][j] = 0;
        }
    }
    matrix[0][0] = 1;
    matrix[m-1][0] = 1;
    for(int i = 1;i<m;i++){
        matrix[i-1][i]=1;
    }
    return matrix;
}

int** caclMatrix(int**& matrix1,int**& matrix2,int m){
    int** res;
    res = (int**)malloc(m*sizeof(int*));
    for(int i =0;i<m;i++){
        res[i] = (int*)malloc(m*sizeof(int));
    }
    for(int i = 0;i<m;i++){
        for(int j =0;j<m;j++){
            res[i][j] = 0;
            for(int k = 0;k<m;k++){
                res[i][j]=(res[i][j]+matrix1[i][k]*matrix2[k][j])%M;
            }
        }
    }
    return res;
}

int** caclMatrixn(int** matrix,LL x,int m){
    if(x==1){
        return matrix;
    }
    int** matrix1 = caclMatrixn(matrix, x/2, m);
    if(x%2==0){
        return caclMatrix(matrix1,matrix1, m);
    }else{
        int** matrix2 = caclMatrix(matrix1,matrix1, m);
        return caclMatrix(matrix2,matrix, m);
    }
}

int main(){
    LL n;
    int m;
    cin>>n>>m;
    if(n<m){
        cout<<1<<endl;
    }else{
        int** matrix = initMatrix(m);
        int** matrix_res = caclMatrixn(matrix, n-m+1, m);
        int res = 0;
        for(int i = 0;i<m;i++){
            res = (res+matrix_res[i][0])%M;
        }
        cout<<res<<endl;
    }
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) x.begin(),x.end()
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ff first
#define ss second
#define mod 1000000007
#define eb emplace_back
#define pb push_back
#define For(i,a,b) for(i=a;i<b;i++)
#define gcd __gcd
#define double long double
#undef endl
#define endl "\n"

int main(void)
{
    boost;
    ll t,i,j,n,c,m,k;
    string s;
    //cin >> t;
    cin >> n >> m;
    ll total = 0;
    c = 0,k = 0;
    ll temp = (n-1)/m;
    total = 1+(((((temp%mod)*((temp+1)%mod))%mod*(n%mod))/2   )%mod);
 //   cout << total << endl;
    total += ((((temp%mod)*((temp+1)%mod))/2   )%mod);
   // cout << total << endl;
    total %= mod;
    total -= (((( m*(((temp)%mod)*((temp+1)%mod))%mod)*((2*temp+1)%mod)   )/6)%mod);
   // cout << total << endl;
    total = (total+mod)%mod;
    if(n%m==0)
        total += 1;
//    while(1)
//    {
//        if(k==0)
//            total = 1;
//        else if(n-c*m>0)
//        tota-l += ((n-c*m+1)*k);
//        else if(n-c*m==0)
//            total += 1;
//        else
//            break;
//        total %= mod;
//        c++;
//        k++;
//        cout << c << " " << k << endl;
//    }

    cout << total%mod;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll sz=200005;
ll n,m,p,MOD=1e9+7;
ll bin[103][103];
void mult_mat(ll m, ll ans[][100], ll bin[][100])
{
    ll mult[m][m];
    for(ll i=0;i<m;i++)
    {
        for(ll j=0; j<m; j++)
        {
            mult[i][j]=0;
            for(ll k=0; k<m; k++)
            {
                mult[i][j]+=ans[i][k]*bin[k][j];
                if(mult[i][j]>=MOD)
                {
                    mult[i][j]%=MOD;
                }
            }
        }
    }
    for(ll i=0; i<m; i++)
    {
        for(ll j=0; j<m; j++)
        {
            ans[i][j]=mult[i][j];
        }
    }
}

void pow_mat(ll n, ll fin[][100], ll m)
{
    ll ans[m][100];
    ll b[m][100];
    for(ll i=0; i<m; i++)
    {
        for(ll j=0; j<m; j++)
        {
            ans[i][j]=bin[i][j];
            b[i][j]=bin[i][j];
        }
    }
    n--;
    while(n>0)
    {
        if(n%2==1)
        {
            mult_mat(m,ans,b);
            n--;
        }
        else
        {
            n=n/2;
            mult_mat(m,b,b);
        }
    }
    for(ll i=0; i<m; i++)
    {
        for(ll j=0; j<m; j++)
        {
            fin[i][j]=ans[i][j];
        }
    }
}
int main()
{
    cin>>n>>m;
    for(ll i=0; i<m; i++)
    {
        for(ll j=0; j<m; j++)
        {
            if(i==0)
                bin[i][j]=1;
            else if(i==j+1)
                bin[i][j]=1;
            else
                bin[i][j]=0;
        }
    }
    ll ans=0;
    ll fin[m+1][100];
    pow_mat(n-m+1,fin,m);
    for(ll i=0; i<m; i++)
        ans=(ans+fin[0][i])%MOD;
    cout<<ans;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
const double pi=2*acos(0.0);
double inff=1.0/0.0;
#define ll           long long int
#define inf          10000000000
#define MOD          1000000007
#define pb           push_back
#define sz(x)        (int)x.size()
#define mp           make_pair
#define lbd          lower_bound
#define ubd          upper_bound
#define ipair        pair<ll,ll>
#define all(v)       v.begin(),v.end()
#define watch(x)     cout<<(#x)<<" is "<<(x)<<endl;
#define rep(a,b,c)   for(a=(int)b;a<(int)c;a++)
#define bac(a,b,c)   for(a=(int)b;a>=(int)c;a--)
#define se           second
#define f            first
#define ios          ios::sync_with_stdio(false), cout.tie(0), cin.tie(0);
#define mem(a,val)   memset(a,val,sizeof a)
#define endl         "\n"
#define mxn          200011
#define vi           vector<ll>
#define vii          vector<ipair>
#define si           set<ll>
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll x,y,n,i,z,j,k,w,u,q,t,m;
ll a[101][101],b[101][101],c[101][101],temp[101][101];
void matmul(ll flag)
{
	mem(temp,0);
	for(int i=0;i<m;i++)
	{
		for(int j=0;j<m;j++)
		{
			for(int k=0;k<m;k++)
			{
				if(flag==1)
				{
					temp[i][j]=(temp[i][j]%MOD+((c[i][k]%MOD)*(c[k][j]%MOD))%MOD)%MOD;
				}
				else
				{
					temp[i][j]=(temp[i][j]%MOD+((c[i][k]%MOD)*(a[k][j]%MOD))%MOD)%MOD;
				}
			}
		}
	}
    rep(i,0,m)
    {
        rep(j,0,m)
        {
            c[i][j]=temp[i][j];
        }
    }
}
void expo(ll n)
{
	if(n==1)
	{
		return;
	}
	expo(n/2);
	matmul(1);
	if(n%2==1)
	{
		matmul(2);
	}
}
void solve()
{
	cin>>n>>m;
	if(n<m)
	{
		cout<<1<<endl;
		return;
	}
	rep(i,0,m)
	{
		b[0][i]=1;
	}
	rep(i,0,m)
	{
		rep(j,0,m)
		{
			if(j==i+1)
			{
				a[i][j]=1;
			}
		}
	}
	a[m-1][0]=1,a[m-1][m-1]=1;
    rep(i,0,m)
    {
        rep(j,0,m)
        {
            c[i][j]=a[i][j];
        }
    }
	expo(n-m+1);
	rep(i,0,m)
	{
		w=((w%MOD)+((c[m-1][i]%MOD)*(b[0][i]%MOD)));
	}
	cout<<w<<endl;
}
int main()
{
    t=1;
    while(t--)
    {
    	solve();
    }
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX  =100;
const int MOD = 1000000007;

typedef ll matrix[MAX][MAX];

matrix iden, in, tmp, ext;
int n;
void cop(matrix a, matrix b)
{
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            a[i][j] = b[i][j];
}

void add(matrix a, matrix b, matrix res)
{
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            res[i][j] = (a[i][j] + b[i][j]) % MOD;
}

void addu(matrix a, matrix b)
{
    add(a, b, tmp);
    cop(a, tmp);
}

void mul(matrix a, matrix b, matrix res)
{
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            res[i][j] = 0;
            for (int k = 0; k < n; k++)
                res[i][j] = (res[i][j] + a[i][k] * b[k][j]) % MOD;
        }
    }
}

void mulu(matrix a, matrix b)
{
    mul(a, b, tmp);
    cop(a, tmp);
}

void pwr(matrix a, ll k, matrix res)
{
    cop(res, iden);
    cop(ext, a);
    while (k)
    {
        if (k & 1)
            mulu(res, ext);
        mulu(ext, ext);
        k >>= 1;
    }
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
	ll k,m;
	cin>>k>>m;
	for(int i=0;i<m;i++){
		iden[i][i] = 1;
	}
	n = m;
	matrix a,b;
	a[0][0]=1;
	a[0][m-1]=1;
	for(int i=1;i<m;i++){
		a[i][i-1] = 1;
	}
	pwr(a,k-1,b);
	ll ans = 0;
	for(int i=0;i<m;i++){
		ans+=b[0][i];
		ans%=MOD;
	}
	cout<<ans<<endl;
	return 0;
}

#include <bits/stdc++.h>

/*#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")
#pragma GCC optimize("vpt")
#pragma GCC optimize("rename-registers")
#pragma GCC optimize("move-loop-invariants")
#pragma GCC optimize("unswitch-loops")
#pragma GCC optimize("function-sections")
#pragma GCC optimize("data-sections")
#pragma GCC optimize("branch-target-load-optimize")
#pragma GCC optimize("branch-target-load-optimize2")
#pragma GCC optimize("btr-bb-exclusive")*/

#define mp make_pair
#define ll long long
#define ld long double
#define pb push_back
#define fast_io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define fs first
#define sc second
#define getfiles ifstream cin("input.txt"); ofstream cout("output.txt");
#define endl '\n'
#define con continue;

const ll INF = 2000000005;
const ll BIG_INF = 2000000000000000005;
const ll mod = 1000000007;
const ld PI = 3.141592653589793238462643;

using namespace std;

vector< pair<ll, ll> > dir = {
    {
        -1, 0
    },
    {
        0, 1
    },
    {
        1, 0
    },
    {
        0, -1
    }
};

bool valid(ll x, ll y, ll n, ll m) {
    return x >= 0 && y >= 0 && x < n && y < m;
}

mt19937 rng(1999999973);

vector< vector<ll> > computeMatrix(vector< vector<ll> > a, vector< vector<ll> > b) {
    vector< vector<ll> > c(a.size(), vector<ll>(b[0].size(), 0));
    for (ll i = 0; i < a.size(); i++) {
        for (ll j = 0; j < b[0].size(); j++) {
            for (ll k = 0; k < a[0].size(); k++) {
                c[i][j] += a[i][k] * b[k][j];
                c[i][j] %= mod;
            }
        }
    }
    return c;
}

vector< vector<ll> > bin_pow(vector< vector<ll> > &p, ll st) {
    if (st == 1)
        return p;
    if (st % 2 == 1) {
        return computeMatrix(bin_pow(p, st - 1), p);
    }
    else {
        vector< vector<ll> > res = bin_pow(p, st / 2);
        return computeMatrix(res, res);
    }
}

signed main() {
    fast_io;

    ll n, m;
    cin >> n >> m;

    vector< vector<ll> > a(1, vector<ll>(m, 1));
    vector< vector<ll> > p(m, vector<ll>(m, 0));
    for (ll i = 0; i < m - 1; i++)
        p[i][i + 1] = 1;
    p[m - 1][0] = 1;
    p[m - 1][m - 1] = 1;

    cout << computeMatrix(a, bin_pow(p, n))[0][0];

    return 0;
}

#include <bits/stdc++.h>
#define ull unsigned long long
#define M 105
#define mod 1000000007

using namespace std;
ull n, m, r[M][M], a[M][M];
void inm(ull r[M][M], ull a[M][M])
{
    ull aux[M][M];
    for(int i=1;i<=m;i++)
        for(int j=1;j<=m;j++)
            aux[i][j]=0;

    for(int i=1;i<=m;i++)
        for(int j=1;j<=m;j++)
            for(int k=1;k<=m;k++)
        {
            aux[i][j]+=r[i][k]*a[k][j];
            aux[i][j]%=mod;
        }
    for(int i=1;i<=m;i++)
        for(int j=1;j<=m;j++)
            r[i][j]=aux[i][j];
}

int main()
{
    cin >> n >> m;

    for(int i=1;i<=m;i++)
        r[i][i]=1;
    for(int i=1;i<m;i++)
        a[i+1][i]=1;
    a[m][m]=a[1][m]=1;

    n=n-m+1;
    while(n>0)
    {
        if(n%2==1)
            inm(r, a);
        inm(a, a);
        n/=2;
    }

    cout << (r[1][m]+r[m][m])%mod;
    return 0;
}

////////////////////////////////////////////
///                                      ///
///         Template ver. 1 rapel        ///
/// Fear is Temporary, Regret is Forever ///
///          Must Try and Get AC         ///
///                                      ///
////////////////////////////////////////////
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <iomanip>

#include <algorithm>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>

#include <math.h>
#include <complex>

#include <assert.h>
#include <time.h>
//#include <chrono>
//#include <random>

#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <bitset>

#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define endl '\n'
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;

void desperate_optimization(int precision){
  	ios_base::sync_with_stdio(false);
  	cin.tie(0);
  	cout.tie(0);
  	cout.setf(ios::fixed);
  	cout.setf(ios::showpoint);
  	cout.precision(precision);
}

const LL MOD = 1e9 + 7;

struct matrix{
	LL arr[2][2];
};

matrix mulmat(matrix &A,matrix &B, LL MOD = 1e9+7) {
	matrix C;
	for(int i = 0;i < 2;i++) {
		for(int j = 0;j < 2;j++) {
			C.arr[i][j] = 0;
			for(int k = 0;k < 2;k++) {
				C.arr[i][j] = (C.arr[i][j] + A.arr[i][k] * B.arr[k][j] % MOD) % MOD;
			}
		}
	}
	return C;
}

LL fp(LL A, LL B) {
	LL res = 1;
	while(B) {
		if(B & 1) res = res * A % MOD;
		B /= 2;
		A = A * A %MOD;
	}
	return res;
}

LL fast(LL x, LL MOD = 1e9+7) {
	if(x <= 0) return 1;
	matrix base, ans;
	for(int i = 0;i < 2;i++) {
		for(int j = 0;j < 2;j++) {
			ans.arr[i][j] = ((i == j)?1:0);
			base.arr[i][j] = 1;
		}
	}
	base.arr[1][1] = 0;
	while(x) {
		if(x & 1) ans = mulmat(ans,base,MOD);
		base = mulmat(base,base,MOD);
		x /= 2;
	}
	return (ans.arr[0][0] + ans.arr[0][1]) % MOD;
}

void hora(int tc) {
	LL n,m;
	cin>>n>>m;
	if(n < m) {
		cout<<1<<endl;
		return ;
	}
	LL ct = fast(1);
	LL bawah = fast(m * 2 - 4);
	LL atas = fast(n + m - 3, bawah);
//	cout<<atas<<" "<<fast(n + m - 3)<<" "<<bawah<<endl;
	if(atas * 2 >= bawah) atas = fast(n + m - 3) + (bawah - atas);
	else atas = fast(n + m - 3) + (MOD - atas);
	atas %= MOD;
	cout<<atas * fp(bawah,MOD - 2) % MOD<<endl;
}

int main(){
	desperate_optimization(10);
	int ntc = 1;
	//cin>>ntc;
	for(int tc = 1;tc <= ntc;tc++) hora(tc);
	return 0;
}

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less
#define MAX 5002
#define pb push_back
#define For(i,s,e) for (ll i=(s); i<(e); i++)
#define Debug_array(a,n) for (ll i=(0); i<(n); i++) cout<<a[i]<<" "
#define Foe(i,s,e) for (ll i=(s); i<=(e); i++)
#define Fod(i,s,e) for (ll i=(s)-1; i>=(e); i--)
#define Mod 1000000007
#define pii pair<ll,ll>
#define fi first
#define se second
#define endl "\n"
#define mp make_pair
#define big_prime 15486277
#define bigger_prime 179424697
#define biggest_prime 32416188691
//#define random_shuffle(indices.begin(), indices.end());
//std::random_device rd;
//std::mt19937 g(rd());
//std::shuffle(v.begin(), v.end(), g);
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;

ll ans[2][2];
ll a[2][2];
ll cache[2][2];

void twice(ll n){
	For(i,0,n) For(j,0,n) ans[i][j]=0;

	For(i,0,n){
		For(j,0,n){
			For(k,0,n){
				ll temp=(cache[i][k]*cache[k][j])%Mod;
				ans[i][j]=(ans[i][j]+temp)%Mod;
			}
		}
	}
	return;
}

void multiply(ll n){
	For(i,0,n) For(j,0,n) ans[i][j]=0;

	For(i,0,n){
		For(j,0,n){
			For(k,0,n){
				ll temp=(a[i][k]*cache[k][j])%Mod;
				ans[i][j]=(ans[i][j]+temp)%Mod;
			}
		}
	}
	return;
}

void asquare(ll n){
	For(i,0,n) For(j,0,n) ans[i][j]=0;

	For(i,0,n){
		For(j,0,n){
			For(k,0,n){
				ll temp=(a[i][k]*a[k][j])%Mod;
				ans[i][j]=(ans[i][j]+temp)%Mod;
			}
		}
	}

	return;
}

void power(ll n,ll k){
	if(k==1){
		For(i,0,n) For(j,0,n) cache[i][j]=a[i][j];
		return;
	}else if(k==2){
		asquare(n);
		For(i,0,n) For(j,0,n) cache[i][j]=ans[i][j];
		return;
	}

	power(n,k/2);
	twice(n);
	For(i,0,n) For(j,0,n) cache[i][j]=ans[i][j];
	if(k%2==0){

	}else{
		multiply(n);
		For(i,0,n) For(j,0,n) cache[i][j]=ans[i][j];
	}
	return;
}

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

	ll n=2;
	ll N,M;cin>>N>>M;
	a[0][0]=1;
	a[0][1]=1;
	a[1][0]=1;
	a[1][1]=0;
	power(n,N-M);
	ll ans=((2*cache[0][0])%Mod+cache[0][1])%Mod;

	cout<<ans<<endl;

}

/*input
3 2

*/

//assic value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) is(65-90) and 32 for space
#include<bits/stdc++.h>
using namespace std;
#define ll          long long
#define pb          push_back
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define vs			vector< string >
#define vvi         vector< vector< ll > >
#define all(it,a)   for(auto it=(a).begin();it!=(a).end();it++)
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define inf         1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define repr(i,a,b) for(ll int i=a;i>b;i--)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define mp          make_pair
#define graph(n)    adj(n,vector< ll > () )

ll n,m;
const ll M = 101;
const ll MOD = 1e9+7;
vvi v(M,vector< ll > (M));

void mul(vvi &a,vvi &b)
{
	vvi ans(m,vector< ll > (m));
	rep(i,0,m)
	{
		rep(j,0,m)
		{
			ans[i][j]=0;
			rep(k,0,m)
				ans[i][j]=(ans[i][j]%MOD+((a[i][k]%MOD)*(b[k][j]%MOD))%MOD)%MOD;
		}
	}

	rep(i,0,m)
		rep(j,0,m)
			v[i][j]=ans[i][j];
}

ll power(ll y)
{
	vvi cpy(m,vector< ll > (m));

	rep(i,0,m)
		rep(j,0,m)
			cpy[i][j]=v[i][j];

	if(y==0)
		return v[0][0];

	if(y!=1)
	{
		power(y/2);
		mul(v,v);
		if(y%2==1)
			mul(v,cpy);
	}

	// cout<<"power = "<<y<<"\n";
	// rep(i,0,m)
	// {
	// 	rep(j,0,m)
	// 	{
	// 		cout<<v[i][j]<<" ";
	// 	}
	// 	cout<<"\n";
	// }

	return (v[0][0]+v[0][m-1])%MOD;
}

ll f(ll n)
{
	rep(i,0,M)
	{
		rep(j,0,M)
		{
			if((i==0 && j==0) || (i==0 && j==m-1) || i-1==j)
				v[i][j]=1;
			else
				v[i][j]=0;
		}
	}

	return power(n-1);
}

int solve()
{
	cin>>n>>m;
	cout<<f(n);

	return 0;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	ll t=1;
	//cin>>t;
	while(t--)
		solve();
}

#include <stdio.h>
#define MOD 1000000007

int matrix[66][100][100];
int src[100][100];
int dest[100][100];

inline int add(int a, int b, int m = MOD)
{
	return (a + b) % m;
}

inline int sub(int a, int b)
{
	return (MOD + a - b) % MOD;
}

inline int prod(int a, int b, int m = MOD)
{
	return (long long)a * b % m;
}

int power(int a, int n, int m = MOD)
{
	if (!n) return 1;
	int mid = power(a, n / 2, m);
	mid = prod(mid, mid, m);
	if (n % 2) mid = prod(mid, a, m);
	return mid;
}

int inverse(int a)
{
	return power(a, MOD - 2);
}

void matmul(int a[100][100], int b[100][100], int c[100][100], int n)
{
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
		{
			int sum = 0;
			for (int k = 0; k < n; k++) sum = add(sum, prod(b[i][k], c[k][j]));
			a[i][j] = sum;
		}
	}
}

void matcpy(int a[100][100], int b[100][100], int n)
{
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++) a[i][j] = b[i][j];
	}
}

void matprint(int a[100][100], int n)
{
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++) printf("%d ", a[i][j]);
		printf("\n");
	}
}

void matpower(long long k, int n)
{
	matcpy(matrix[0], src, n);
	for (int i = 0; i < n; i++) matrix[65][i][i] = 1;
	for (int i = 0; i < 63; i++)
	{
		matmul(matrix[i + 1], matrix[i], matrix[i], n);
		if ((k >> i) & 1)
		{
			matmul(matrix[64], matrix[65], matrix[i], n);
			matcpy(matrix[65], matrix[64], n);
		}
	}
	matcpy(dest, matrix[65], n);
}

int main()
{
	long long N;
	int M;
	scanf("%I64d %d", &N, &M);
	for (int i = 1; i < M; i++) src[i - 1][i] = 1;
	src[M - 1][0] = 1;
	src[M - 1][M - 1] = 1;
	matpower(N - M + 1, M);
	printf("%d\n", add(dest[M - 1][0], dest[M - 1][M - 1]));
	return 0;
}

#include <bits/stdc++.h>

typedef long long ll;
using namespace std;

const ll MOD = 1000000007;
unordered_map<ll,ll> Fib;

ll fib(ll n)
{
    if(n<2) return 1;
    if(Fib.find(n) != Fib.end()) return Fib[n];
    Fib[n] = (fib((n+1) / 2)*fib(n/2) + fib((n-1) / 2)*fib((n-2) / 2)) % MOD;
    return Fib[n];
}

int main()
{
//    while(1){
        ll n,m;
        cin>>n>>m;
        cout << fib(n-m+2) << "\n";
  //  }
}

#include <bits/stdc++.h>
#define ull unsigned long long
#define M 105
#define mod 1000000007

using namespace std;
ull n, m, r[M][M], a[M][M], s;
void inm(ull r[M][M], ull a[M][M])
{
    ull aux[M][M];

    for(int i=1;i<=m;i++)
        for(int j=1;j<=m;j++)
            {
                aux[i][j]=0;
                for(int k=1;k<=m;k++)
                    {
                        aux[i][j]+=(r[i][k]*a[k][j])%mod;
                        aux[i][j]%=mod;
                    }
            }
    for(int i=1;i<=m;i++)
        for(int j=1;j<=m;j++)
            r[i][j]=aux[i][j];
}

int main()
{
    cin >> n >> m;

    for(int i=1;i<=m;i++)
        r[i][i]=1;
    for(int i=1;i<m;i++)
        a[i+1][i]=1;
    a[m][m]=a[1][m]=1;

    if(m<n)
    {
        cout << 1;
        return 0;
    }
    while(n>0)
    {
        if(n%2==1)
            inm(r, a);
        inm(a, a);
        n/=2;
    }

    for(int i=1;i<=m;i++)
        s=(s+r[i][m])%mod;
    cout << s;
    return 0;
}

#include<iostream>
#include <bits/stdc++.h>
#define ll unsigned long long
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define mod 1000000007
using namespace std;
int main(){
	ios_base::sync_with_stdio(0); cin.tie(NULL);
	ll a,b;
	cin >> a >> b;
	ll d = a / b;
	ll ans = (1 + (d % mod + ((d % mod) * a) % mod) % mod) % mod;
	d = ((((d % mod) * ((d + 1) % mod)) % mod) * 500000004) % mod;
	d = (d * b) % mod;
	ans = (ans - d) % mod;
	if(ans < 0) ans += mod;
	cout << ans << "\n";
	return 0;
}

#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define y1 yy1

using namespace std;

const int N=200005;
const ll mod=1000000007;

ll dp[100005];
ll n,k;

ll m[105][105];
ll mat[105][105];
ll one[105][105];
ll res[105][105];

void mult(ll a[105][105],ll b[105][105])
{
          ll res[105][105];
          for(int i=0;i<k;i++)
                    for(int j=0;j<k;j++)
                              res[i][j]=0;

          for(int i=0;i<k;i++)
                    for(int j=0;j<k;j++)
                              for(int p=0;p<k;p++)
                                        res[i][j]=(res[i][j]+a[i][p]*b[p][j])%mod;

          for(int i=0;i<k;i++)
                    for(int j=0;j<k;j++)
                              a[i][j]=res[i][j];
}

void bpow(ll x)
{
          while(x)
          {
                    if(x&1)
                              mult(mat,m);
                    mult(m,m);
                    x>>=1;
          }
}

int main()
{
          ios_base::sync_with_stdio(0);
          //freopen("INPUT.txt","r",stdin);
          cin>>n>>k;
          k++;
          m[0][0]=1;
          m[k-1][0]=1;
          for(int i=0;i<k;i++)
                    m[i-1][i]=1;

          for(int i=0;i<k;i++)
                              mat[i][i]=1;
          dp[0]=1;

          for(int i=1;i<=k;i++)
                              dp[i]=(dp[i-1]+(i-k>=0 ? dp[i-k] : 0))%mod;

         bpow(n-k+2);

          cout<<(dp[k]*mat[0][0]+dp[1]*mat[0][k-1])%mod;

}

/*---------------------------"ANJAN AGARWALA"------------------------
----------------------------------@anjn98---------------------------*/

//		#define opti
#ifdef opti
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#endif

#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
ll power(ll x,ll y,ll p){ll r=1; x=x%p; while(y){ if(y&1) r= r*x%p; y=y>>1; x=x*x%p; } return r; }
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;*/

#define IO 				ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define FILEIO 			freopen("input.txt", "r", stdin); freopen("out.txt", "w", stdout);
#define all(v) 			v.begin(),v.end()
#define PR(a) 			cout<<"("<<a<<")";
#define ED 				cout<<'\n';
#define endl 			'\n'
#define loop(j,a,n) 	for(int j=a;j<=n;j++)
#define loop1(j,a,n) 	for(int j=a;j>=n;j--)
#define fr1(j,n) 		for(int j=0;j<n;j++)
#define fr(n) 			for(int i=0;i<n;i++)
#define trav(x,s)       for(auto x:s)
#define PB 				push_back
#define MP 				make_pair
#define pii 			pair<int,int>
#define pll 			pair<long long int,long long int>
#define F 				first
#define S 				second
#define binf 			2000000000000000001
#define mod 			1000000007

ll n,m;
const int N=1e5+99;

ll fac[N],inv[N];
vector<ll> dv[N];int mu[N],prime[N];

void pre()
{
	inv[0]=fac[0]=1;
	for(ll i=1;i<N;i++) fac[i]=(fac[i-1]*i)%mod,mu[i]=1;

	inv[N-1]=power(fac[N-1],mod-2,mod);
	for(int i=N-2;i>=0;i--) inv[i]=((i+1LL )*inv[i+1])%mod;

	for(int i=1;i<N;i++)
		for(int j=i;j<N;j+=i)dv[j].PB(i);

	prime[0]=prime[1]=1;
	for(int i=2;i<N;i++)
		if(!prime[i]) for(int j=i+i;j<N;j+=i)prime[j]=1		;

	for(int i=2;i*i<N;i++)
	{
		int t=i*i;
		for(int j=t;j<N;j+=t) mu[j]=0;
	}

	for(int i=1;i<N;i++)
	{
		if(!mu[i]) continue;
		int prt=0;
		trav(x,dv[i]) if(!prime[x] ) prt++;
		mu[i]=(prt%2) ? -1:1;

	}

}
ll ncr(ll n,ll 	r){ 	ll ans= (fac[n] * inv[r])%mod;	ans = (ans* inv[n-r])%mod;	return n>=r?ans:0;}

// DONT FORGET TO CALL PRE() IN THE MAIN() FUNCTION

int32_t main()
{
	IO
	#ifndef ONLINE_JUDGE
	FILEIO
	#endif
	pre();

	for(int i=1;i<=10;i++)
	{
		for(int j=1;j<=10;j++)
		{
			ll ans=1;
			for(int k=1;k<=j*m;k++)
			{
				ll req= n - m*(k-1);
				ans+=ncr(req,k);
			}
			PR(i)PR(j) PR(ans)ED

		}

	}

}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ii pair<int,int>
#define mp make_pair
#define pb push_back

// look at for learning "matrix exponentiation":

/*///////////////////////////////////////////////////////////////////////////
http://fusharblog.com/solving-linear-recurrence-for-programming-contest/

ye filme youtube eee 20 daygeiii ham bud....... vase fibonatchi logn peyda kardanesh
///////////////////////////////////////////////////////////////////////////*/

#define MOD 1000000007
typedef vector<vector<ll> >matrix;

matrix one(int sz)
{
	matrix ret;
	ret.resize(sz);
	for(int i=0;i<ret.size();i++)
	{
		ret[i].resize(sz);
		for(int j=0;j<ret.size();j++)
		ret[i][j]=(i==j);
	}
	return ret;
}

matrix mult(matrix a,matrix b)
{
	matrix ret;
	ret.resize(a.size());
	for(int i=0;i<ret.size();i++){
		ret[i].resize(a.size());
		for(int j=0;j<ret.size();j++)
			ret[i][j]=0;
	}
	for(int k=0;k<ret.size();k++){
		for(int i=0;i<a.size();i++){
			for(int j=0;j<b.size();j++){
				ret[i][j]=(ret[i][j]+a[i][k]*b[k][j]);
				ret[i][j]%=MOD;
			}
		}
	}
	return ret;
}

matrix pw(matrix a,ll b)
{
	if(b==0)
		return one((int)a.size());
	if(b%2)
		return mult(a,pw(a,b-1));
	return pw(mult(a,a),b/2);
}

ll n,m;
matrix dp;

int main()
{
    ios_base::sync_with_stdio(0);

    cin>>n>>m;

    dp.resize(m);
    for(int i=0;i<m;i++){
    	dp[i].resize(m);
    }

    for(int i=0;i<m;i++){
    	for(int j=0;j<m;j++){
    		dp[i][j]=0;
    	}
    }

    dp[0][0]=dp[0][m-1]=1;
    for(int i=0;i<m-1;i++){
    	dp[i+1][i]=1;
    }
    dp=pw(dp,n-m+1);
    int ans=0;
    for(int i=0;i<m;i++) ans+=dp[i][0];
//    dp=pw(dp,n);
    cout<<ans<<endl;
}

//BROWNIE TK

#include <bits/stdc++.h>
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ldb;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define pb push_back
#define popb pop_back()
#define pf push_front
#define popf pop_front()
#define si size()
#define be begin()
#define en end()
#define all(v) v.be, v.en
#define le length()
#define mp make_pair
#define mt make_tuple
#define acc(v) accumulate(all(v),0)
#define F first
#define S second

#define forz(i, n) for (int i = 0; i < n; i++)
#define forzm(i, m, n) for (int i = m; i < n; i++)
#define rforz(i, n) for (int i = n - 1; i >= 0; i--)
#define rforzm(i, m, n) for (int i = n - 1; i >= m; i--)
#define deci(n) fixed << setprecision(n)
#define high(n) __builtin_popcount(n)
#define highll(n) __builtin_popcountll(n)
#define parity(n) __builtin_parity(n)
#define ctz(n) __builtin_ctz(n)
#define lb lower_bound
#define ub upper_bound
#define er equal_range
#define maxe *max_element
#define mine *min_element
#define mod 1000000007
#define mod2 998244353
#define gcd __gcd
#define kira ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)

#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl

#define oset tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define osetlli tree<lli, null_type, less<lli>, rb_tree_tag, tree_order_statistics_node_update>
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set
#define ofk order_of_key
#define fbo find_by_order
using namespace std;

/*STD fucntions*/
lli power(lli x, lli y, lli p)
{
    lli res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        //y must be even now
        y = y >> 1; //y=y/2
        x = (x * x) % p;
    }
    return res;
}
lli modi(lli a, lli m)
{
    // fermat little thm where m is prime
    return power(a, m - 2, m);
}
/*CODE BEGINS*/
struct matrix
{
    vector <vector <lli>>m;
};
void msi(matrix &m,lli a,lli b)
{
    m.m.resize(a);
    forz(i,a)
       m.m[i].resize(b);
}
void minit(matrix &m,lli x)
{
    forz(i,m.m.size())
       forz(j,m.m[0].size())
           m.m[i][j]=x;
}
matrix mul(matrix m1,matrix m2)
{
    matrix m3;
    msi(m3,m1.m.size(),m2.m[0].size());
    forz(i,m3.m.size())
      {
          forz(j,m3.m[0].size())
          {    m3.m[i][j]=0;
               forz(k,m1.m[0].size())
                 m3.m[i][j]=(m3.m[i][j]+m1.m[i][k]*m2.m[k][j])%mod;
          }
      }
      return m3;
}
matrix mexp(matrix &mx,lli p)
{
   matrix res;
   msi(res,mx.m.size(),mx.m.size());
   minit(res,0);
   forz(i,mx.m.size())
      res.m[i][i]=1;
   while(p>0)
   {
     if(p&1)
       res=mul(res,mx);
     mx=mul(mx,mx);
     p=p>>1;
   }
   return res;
}
int main()
{
    kira;
    lli n,m;
    cin>>n>>m;
    matrix ans;
    msi(ans,m,m);
    minit(ans,0);
    ans.m[0][0]=1;
    ans.m[0][m-1]=1;
    for(int i=1;i<m;i++)
    {
        ans.m[i][i-1]=1;
    }
    ans=mexp(ans,n-m);
    cout<<(2*ans.m[0][0]+ans.m[0][m-1])%mod;
    return 0;
}

#include<bits/stdc++.h>
#define fi first
#define se second
#define mk make_pair
#define pb push_back
#define INF 1e9+9
#define lowbit(n) n&-n
using namespace std;
const int maxn=100001;
typedef long long ll;
int n;

#define MOD 10000ll
#define MAX_N 2

template<typename T, int N = 1>
struct Matrix {
    Matrix(int f = 0) : n(sizeof(data[0]) / sizeof(data[0][0])) {
        for (int i = 0; i < n; i++)
            for (int j = 0; j < n; j++)
                data[i][j] = T(0);
        if (f)
            for (int i = 0; i < n; data[i][i] = T(1), ++i) {}
    }
    Matrix operator * (const Matrix& other) const {
        Matrix<T, N> ret;
        for (int i = 0; i < n; i++)
            for (int j = 0; j < n; j++)
                for (int k = 0; k < n; k++)
                    ret.data[i][j] = (ret.data[i][j] + data[i][k] * other.data[k][j] % MOD) % MOD;
        return ret;
    }
    Matrix operator + (const Matrix& other) const {
        Matrix<T, N> ret;
        for (int i = 0; i < n; i++)
            for (int j = 0; j < n; j++)
                ret.data[i][j] = (data[i][j] + other.data[i][j]) % MOD;
        return ret;
    }
    Matrix& operator % (const ll mod) {
        return *this;
    }
    T data[N][N];
    int n;
};
template<typename T>
T mul(T a, ll n, ll mod)
{
    T ret(1);
    for (; n; n >>= 1) {
        ret = ret * (n & 1 ? a : T(1)) % mod;
        a = a * a % mod;
    }
    return ret;
}
const ll modulu[MAX_N][MAX_N] = {
    {1, 1},
    {1, 0}
};
void output()
{
	int m;
    for (ll n; cin >> n >>m&& n + 1; )
	{
        Matrix<ll,101> a;
        a.data[0][m-1]=a.data[0][0]=1;
        for(int i=1;i<m;i++)
        	a.data[i][i-1]=1;
        ll mod=1000000007;
		Matrix<ll,101> ans=mul(a,n-m+1,mod);
		ll an=0;
		for(int i=0;i<m;i++)
		{
			an=(an+ans.data[0][i])%mod;
		}
		cout<<an<<endl;
        //memcpy(a.data, modulu, sizeof(modulu));
        //cout << mul(a, n, MOD).data[0][1] << endl;
    }
    return ;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	output();
}

#include <bits/stdc++.h>

using namespace std;

typedef long long int lli;

#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define MOD (lli)1000000007

int m;

lli** mult(lli** A, lli** B)
{
    lli** C = (lli**)malloc(m * sizeof(lli*));
    for (int i = 0; i < m; i++)
        C[i] = (lli*)malloc(m * sizeof(lli));

    for (int i = 0; i < m; i++) {
        for (int j = 0; j < m; j++) {
            for (int k = 0; k < m; k++) {
                C[i][j] += ((A[i][k] % MOD) * (B[k][j] % MOD)) % MOD;
                if(C[i][j] > MOD) C[i][j] -= MOD;
            }
        }
    }

    return C;
}

lli** expM(lli** A, lli n)
{
    if (n == 1)
        return A;
    else if ((n % 2) == 1)
        return mult(A, expM(A, n - 1));
    else
        return mult(expM(A, n / 2), expM(A, n / 2));
}

int main()
{
    lli n;
    cin >> n >> m;

    lli** T = (lli**)malloc(m * sizeof(lli*));
    for (int i = 0; i < m; i++)
        T[i] = (lli*)malloc(m * sizeof(lli));
    for (int i = 0; i < m; i++) {
        for (int j = 0; j < m; j++)
            T[i][j] = 0;
    }
    for (int i = 0; i < m - 1; i++)
        T[i][i + 1] = 1;
    T[m - 1][0] = 1;
    T[m - 1][m - 1] = 1;

    lli** expT = expM(T, n - 1);

    lli ans = 0;

    for (int j = 0; j < m - 1; j++) {
        ans += expT[0][j];
        if(ans > MOD) ans -= MOD;
    }
    ans += (expT[0][m-1]%MOD + expT[0][m-1]%MOD)%MOD;
    if(ans > MOD) ans -= MOD;

    printf("%lld\n", ans);
    return 0;
}

#include <bits/stdc++.h>
#define int int64_t
using namespace std;

const int MOD = 1e9 + 7;

typedef vector<vector<int>> vvi;

vvi multiply(vvi a, vvi b){
    int n = a.size();
    int m = a[0].size();

    int p = b[0].size();
    vvi res(n, vector<int>(p));
    for(int i = 0; i < n; i++){
        for(int j = 0; j < p; j++){
            res[i][j] = 0;
            for(int k = 0; k < m; k++){
                res[i][j] += a[i][k] * b[k][j];
            }
        }
    }
    return res;
}

vvi binpow(vvi a, int p){
    if(p == 1){
        return a;
    }
    if(p % 2 == 0){
        vvi t = binpow(a, p / 2);
        return multiply(t, t);
    }
    vvi t = binpow(a, p - 1);
    return multiply(a, t);
}

signed main(){
    int n, m;
    n = 3;
    m = 2;
    vector<int> a(m, 1);
    vvi matrix(m, vector<int>(m, 0));
    for(int i = 0; i < m - 1; i++){
        matrix[i][i + 1] = 1;
    }
    matrix[m - 1][m - 1] = 1;
    matrix[m - 1][0] = 1;
    matrix = binpow(matrix, n);
    int ans = 0;
    for(int i = 0; i < m; i++){
        ans += a[i] * matrix[i][0];
    }
    cout << ans;
}

#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
using namespace std;
#define MOD 1000000007  //1e9 + 7
#define ll long long
int m;
typedef vector<vector<int> > matrix;

matrix mul(matrix A, matrix B) {
    matrix C(m+1, vector<int>(m+1));
    for (int i = 1; i <= m; i++) {
        for (int j = 1; j <= m; j++) {
            for (int k = 1; k <= m; k++) {
                //ll a = A[i][k], b = B[k][j];
                //ll c = (a * b) % MOD;
                //C[i][j] = (C[i][j] + (int)c) % MOD;
                C[i][j] = (C[i][j] + (A[i][k]*B[k][j]) % MOD) % MOD;
            }
        }
    }
    return C;
}

matrix pow(matrix A, ll p) {
    if (p == 1)
        return A;
    if (p & 1)
        return mul(A, pow(A, p-1));
    matrix X = pow(A, p/2);
    return mul(X, X);
}

int32_t main() {
    IOS;
    int i, j;
    ll n, ans = 0;
    cin >> n >> m;
    if (n < m)
        return cout << 1, 0;
    if (n == m)
        return cout << 2, 0;
    matrix T(m+1, vector<int>(m+1));
    T[1][1] = T[1][m] = 1;
    for (i = 2; i <= m; i++)
        T[i][i-1] = 1;
    vector<int> F(m+1, 1);
    F[1] = 2;
    T = pow(T, n-m);
    for(i = 1; i <= m; i++)
        ans = (ans + T[1][i]*F[i]) % MOD;
    cout << ans;
    return 0;
}

#include <iostream>
using namespace std;
typedef long long ll;

const ll mod = 1e9 + 7;
ll N , M;

struct Matrix{
  static const int maxn = 105;
  ll A[maxn][maxn];
  int n;

  Matrix(int n_): n(n_) {
    for(int i = 0; i < n; ++i)
      for(int j = 0; j < n; ++j)
        A[i][j] = 0;
  }

  Matrix operator * (const Matrix& o) const {
    Matrix ret(n);
    for(int i = 0; i < n; ++i)
      for(int j = 0; j < n; ++j)
        for(int k = 0; k < n; ++k){
          ll c = A[i][k] * o.A[k][j] % mod;
          ret.A[i][j] = (ret.A[i][j] + c) % mod;
        }
    return ret;
  }

  static Matrix identity(int n){
    Matrix ret(n);
    for(int i = 0; i < n; ++i)
      ret.A[i][i] = 1;
    return ret;
  }

  Matrix operator ^ (long long k) const {
    Matrix ret = identity(n);
    Matrix a = *this;
    while(k){
      if(k & 1)ret = ret * a;
      a = a * a;
      k /= 2;
    }
    return ret;
  }

};

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> N >> M;
  Matrix a(M);
  a.A[0][0] = a.A[0][M - 1] = 1;
  for(int i = 1; i < M; ++i){
    a.A[i][i - 1] = 1;
  }
  a = a ^ (N - M + 1);
  ll ret = 0;
  for(int i = 0; i < M; ++i){
    ret = (ret + a.A[0][i]) % mod;
  }
  cout << (ret + mod) % mod << endl;
}

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define sz(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define int long long
#define pii pair<int, int>
#define pip pair<ll, pii>
//#define x first
//#define y second
typedef vector <vector <ll> > matrix;
int mod = 1e9+7;

matrix operator * (const matrix &a, const matrix &b) {
	matrix c(sz(a), vector <ll>(sz(b[0])));
	for (int i = 0; i < sz(a); ++i)
		for (int k = 0; k < sz(b); ++k)
			for (int j = 0; j < sz(b[0]); ++j) {
				c[i][j] = (c[i][j] + a[i][k] * b[k][j]) % mod;
			}
	return c;
}

matrix mpow(matrix a, int p) {
    int m = sz(a[0]);
    matrix c = a;
    while (p) {
        if (p & 1) {
            a = a * c;
            --p;
        }
        p /= 2;
        c = (c* c);
    }
    return a;
}

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, m;
    cin >> n >> m;
    matrix c(m, vector <int> (m));
    for (int i = 0; i < m - 1; ++i) {
        c[i][i + 1] = 1;
    }
    if (n == 1) {
        cout << 1;
        return 0;
    }
    for (int i = 0; i < m; ++i)
        c[m - 1][i] = 1;
   /* for (int i = 0; i < m; ++i) {
        for (int j = 0; j < m; ++j)
            cout << c[i][j] << " ";
        cout << endl;
    }*/
    c = mpow(c, n - 1);
   /* for (int i = 0; i < m; ++i) {
        for (int j = 0; j < m; ++j)
            cout << c[i][j] << " ";
        cout << endl;
    }*/
    cout << c[m - 1][m - 1];
    return 0;
}

#include <bits/stdc++.h>
#define mod 1000000007
using namespace std;
int dp[1000],n,m;
struct node
{
	int l;
	int a[200][200];
	void init()
	{
		for (int i=1;i<=l;i++)
		{
			a[i][i]=1;
		}
	}
};
node operator * (node x,node y)
{
	node ans;
	ans.l=x.l;
	memset(ans.a,0,sizeof(ans.a));
	for (int i=1;i<=x.l;i++)
	{
		for (int j=1;j<=x.l;j++)
		{
			for (int k=1;k<=x.l;k++)
			{
				ans.a[i][j]=(ans.a[i][j]+x.a[i][k]*y.a[k][j]%mod)%mod;
			}
		}
	}
	return ans;
}
node m_pow(node a,int b)
{
	node ans;
	ans.l=a.l;
	ans.init();
	while (b>0)
	{
		if (b&1)
		  ans=ans*a;
		a=a*a;
		b>>=1;
	}
	return ans;
}
int main()
{
	scanf("%d%d",&n,&m);
	dp[0]=1;
	for (int i=1;i<=m;i++)
	{
		dp[i]=(dp[i]+dp[i-1])%mod;
		if (i-m>=0)
		  dp[i]=(dp[i]+dp[i-m])%mod;
	}
	node s,t;
	memset(s.a,0,sizeof(s.a));
	memset(t.a,0,sizeof(t.a));
	s.l=t.l=m;
	for (int i=1;i<=m;i++)
	  s.a[i][1]=dp[m-i+1];
	t.a[1][1]=1;
	t.a[1][m]=1;
	for (int i=2;i<=m;i++)
	  t.a[i][i-1]=1;
	t=m_pow(t,n-m);
	s=t*s;
	printf("%d\n",s.a[1][1]);
}

#include <bits/stdc++.h>
using namespace std;
#define ss second
#define ff first
#define pb push_back
#define eb emplace_back
#define loop(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define len(a) (int)(a).size()
#define allv(a) (a).begin(),(a).end()
using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3fLL;
const double err = 1e-9;
const int mod = 1e9+7;
const int N = 100;

int n,m;

struct Mat{
	ll ma[N][N];
	Mat(){memset(ma,0,sizeof ma);}
	void id(){for(int i=0;i<m;i++)ma[i][i]=1;}
	Mat operator* (const Mat &a)const{
		Mat r;
		for(int i=0;i<m;i++)
			for(int j=0;j<m;j++)
				for(int k=0;k<m;k++)
					r.ma[i][j]=(r.ma[i][j]+ma[i][k]*a.ma[k][j])%mod;
		return r;
	}
};

int main(){
	ios::sync_with_stdio(0);cin.tie(NULL);
	cin>>n>>m;
	Mat r,a;
	r.id();
	a.ma[0][0] = a.ma[0][m-1] = 1LL;
	for(int i=1;i<m;i++)a.ma[i][i-1]=1;
	while(n){
		if(n&1LL)r = r*a;
		a=a*a;
		n>>=1;
	}
	cout<<r.ma[0][0]<<endl;
	return 0;
}

#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
#define LL long long
const LL MOD=1000000007;
const int MAX=120;
int f[MAX+10];
struct Martix{
    LL a[MAX+10][MAX+10];
};
LL m,n;
Martix mul(Martix a,Martix b){
    Martix ret;
    for(int i=1;i<=m;i++){
        for(int j=1;j<=m;j++){
                ret.a[i][j]=0;
            for(int k=1;k<=m;k++){
               (ret.a[i][j]+=((a.a[i][k]*b.a[k][j]%MOD)))%MOD;
            }
        }
    }
    return ret;
}
void print(Martix );
Martix qpow(Martix a,LL x){
    Martix ret;memset(ret.a,0,sizeof(ret.a));

    for(int i=1;i<=m;i++) ret.a[i][i]=1;
    while(x){

        if(x&1) ret=mul(ret,a);
        x>>=1;
        a=mul(a,a);
     //   print(ret);
    }

    return ret;
}
void print (Martix a){
    printf("@@@@\n");
    for(int i=1;i<=m;i++){
        for(int j=1;j<=m;j++){
            printf(" %lld",a.a[i][j]);
        }
        printf("\n");
    }
    printf("@@@@\n");
}
int main(void){
    cin>>n>>m;
    Martix a;
    a.a[1][1]=a.a[1][m]=1;
    for(int i=2;i<=m;i++){
        a.a[i][i-1]=1;
    }
    for(int i=1;i<=m;i++){
        f[i]=1;
    }
    f[m]++;
    LL x=n-m;
    if(x<0) printf("1");
    else if(x==0) printf("2");
    else {
        Martix ret=qpow(a,x);
        LL ans=0;
        for(int i=1;i<=m;i++)
        ans= (ans+f[i]*ret.a[1][m-i+1])%MOD;
        cout<<ans%MOD;
    }
    return 0;

}

#include <bits/stdc++.h>
#define mod 1000000007

using namespace std;
typedef long long INT;
#define NN 110
int m;
int ans[NN][NN];
int a[NN][NN];
int tp[NN][NN];
void multi(int a[NN][NN],int b[NN][NN],int c[NN][NN]){
	for(int i=1;i<=m;i++){
		for(int j=1;j<=m;j++){
			tp[i][j]=0;
			for(int k=1;k<=m;k++){
				tp[i][j]=(tp[i][j]+(INT)a[i][k]*b[k][j])%mod;
			}
		}
	}
	for(int i=1;i<=m;i++){
		for(int j=1;j<=m;j++) c[i][j]=tp[i][j];
	}
}
int main() {
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif
	INT n;
	scanf("%I64d%d",&n,&m);
	a[1][1]=1;
	a[1][m]=1;
	for(int i=2;i<=m;i++){
		for(int j=1;j<m;j++){
			if(i==(j+1)) a[i][j]=1;
		}
	}
	for(int i=1;i<=m;i++){
		for(int j=1;j<=m;j++){
			if(i==j) ans[i][j]=1;
		}
	}
	n-=m;
	while(n){
		if(n&1) multi(ans,a,ans);
		multi(a,a,a);
		n/=2;
	}
	int res=(INT)ans[1][1]*2%mod;
	for(int i=2;i<=m;i++){
		res+=ans[1][i];
		res%=mod;
	}
  	printf("%d\n",res);
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define pb push_back
//#all(x) (x).begin(),(x).end()
#include <chrono>

int const MOD = 1e9 + 7;

ll bigmod(ll a, ll b)
{
    if (b == 0)
        return 1 % MOD;
    ll x = bigmod(a, b / 2);
    x = (x * x) % MOD;
    if (b % 2)
        x = (x * a) % MOD;
    return x;
}

int const N = 3e5 + 10; //;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

ll dp[N] ;
ll n, m;
struct mat{
    ll mt[105+1][105+1];
    mat() {
        memset(mt,0,sizeof mt);
    }
    void identity()
    {
        for(int i = 1; i <= m; i++)
        {
            for(int j = 1; j <= m; j++)
                mt[i][j] = (i == j) ;
        }
    }

};

mat mul(mat &a, mat &b)
{
    mat res;
    for (int i = 1; i <= m; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            for (int k = 1; k <= m; k++)
            {
                res.mt[i][j] += a.mt[i][k] * b.mt[k][j];
                res.mt[i][j] %= MOD;
            }
        }
    }
    return res;
}

mat matExpo(mat a, ll po)
{
    cout << po << endl;
    if(po == 0) {
        mat tmp;
        tmp.identity();
        return tmp;
    }
    mat tmp = matExpo(a,po/2);
    tmp = mul(tmp,tmp);
    if(po % 2 ) {
        tmp = mul(tmp,a);
    }
    return tmp;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);

    cin >> n >> m;

    dp[1] = dp[0] = 1;
    for(int i = 2; i <= 50000; i++)
        dp[i] = (dp[i-1] + ((i >= m )?dp[i - m ] : 0)) % MOD;

    if(n < 5000) {
        cout << dp[n] << '\n';
        return 0;
    }
    mat maker;

    for(int i = 1; i <= m; i++)
    {

            if(i == 1){
                maker.mt[i][1] = maker.mt[i][m] = 1;
            }
            else {
                maker.mt[i][i-1] = 1;
            }

    }

    /* for(int i = 1; i <= m; i++)
    {
        for(int j = 1; j <= m; j++)
        {
            cout  << maker.mt[i][j] << " ";
        }
        cout << endl;
    } */
    //cout << n << " " << m << endl;
    maker = matExpo(maker,n-m) ;
    //cout << n << " " << m << endl;
    //maker = mul(maker, maker);
 /*    for (int i = 1; i <= m; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            cout << maker.mt[i][j] << " ";
        }
        cout << endl;
    }
 */
    int x = 0;
    x++;

    ll ans = 0;
    for(int i = 1; i <= m ; i++)
    {
        ans = (ans + maker.mt[1][i]* dp[m+1-i]) % MOD;
    }

    cout << ans << endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
const int M=102,p=1e9+7;
#define L long long
L n;int m,_n,a;
struct P {
	int w[M][M];
	void Clr() {
		memset(w,0,sizeof w);
	}
	P operator * (const P &a)
		const {
			P u;u.Clr();
			for(int i=0;i<=_n;i++)
				for(int q=0;q<=_n;q++) {
					if(!w[i][q]) continue;
					for(int j=0;j<=_n;j++)
						(u.w[i][j]+=1ll*w[i][q]*a.w[q][j]%p)%=p;
				}
			return u;
		}
} A,U;
P Pow(P a,L t) {
	P u;u.Clr();
	for(int i=0;i<=_n;i++) u.w[i][i]=1;
	for(;t;t>>=1,a=a*a)
		if(t&1) u=u*a;return u;
}
int main() {
	scanf("%I64d%d",&n,&m);_n=m-1;
	for(int i=1;i<m;i++) A.w[i][i-1]=1;
	A.w[0][m-1]=A.w[m-1][m-1]=1;
//	for(int i=0;i<m;i++) {
//		for(int j=0;j<m;j++) cout<<A.w[i][j]<<" ";cout<<endl;
//	}
	A=Pow(A,n);
	for(int i=0;i<m;i++) a=(a+A.w[0][i])%p;
	printf("%d\n",a);
return 0;
}

#include<iostream>
#include<stdio.h>
#include<cstring>
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
const ll mod = 1e9+7;
mat mul(mat a,mat b)
{
    int n=a.size();
    mat c(n,vec(n));
    for(int i=0;i<n;++i)
        for(int j=0;j<n;++j)
            for(int k=0;k<n;++k) {
                c[i][j]+=a[i][k]*b[k][j];
                if(c[i][j]>=mod) c[i][j]-=mod;
            }
    return c;
}
mat pow(mat a,ll b)
{
    ll n = a.size();
    mat c(n,vec(n));
    for(int i=0;i<n;++i) c[i][i]=1;
    while(b)
    {
        if(b&1) c=mul(c,a);
        a=mul(a,a);
        b>>=1;
    }
    return c;
}
int main()
{
    ll n,m;
    cin>>n>>m;
    if(n<m) {cout<<1<<endl;return 0;}
    mat a(m,vec(m));
    for(int i=1;i<m;++i) a[i][i-1]=1;
    a[0][0]=1,a[0][m-1]=1;
    mat c = pow(a,n-m+1);
    ll ans = 0;
    for(int i=0;i<m;++i) ans+=c[0][i];
    cout << ans%mod << endl;
}

#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define IOS ios::sync_with_stdio(0);cin.tie(0);
#define de(x,y) cout<<#x<<" :"<<x<<y;
#define int long long
#define SZ(xx) ((int)xx.size())
#define lowbit(xx) (xx&(-xx))
#define pb push_back
typedef pair<int,int> pii;

const int maxn = 1e2+5;
const int mod = 1e9+7;
int n, m;
struct Matrix {
	int arr[maxn][maxn];

	void init() {
		memset(arr, 0, sizeof(arr));
	}

	void I() {
		for(int i=1; i<=100; i++) {
			arr[i][i] = 1;
		}
	}

	Matrix operator * (const Matrix &a) const {
		Matrix tmp;
		tmp.init();
		for(int i=1; i<=100; i++) {
			for(int j=1; j<=100; j++) {
				for(int k=1; k<=100; k++) {
					tmp.arr[i][j] = tmp.arr[i][j] + a.arr[i][k] * arr[k][j];
					tmp.arr[i][j] %= mod;
				}
			}
		}
		return tmp;
	}
};

Matrix fast_pow(int k) {
	Matrix tmp, a;
	tmp.I();
	a.init();
	a.arr[1][1] = a.arr[1][m] = 1;
	for(int i=2; i<=m; i++) {
		a.arr[i][i-1] = 1;
	}
	while(k) {
		if(k & 1) {
			tmp = tmp * a;
		}
		a = a*a;
		k>>=1;
	}
	return tmp;
}

main() {

	cin >> n >> m;

	if(n < m) {
		cout << 1;
		return 0;
	}

	else {
		Matrix fn = fast_pow(n-m+1);
		cout << (fn.arr[1][1] + fn.arr[1][m]) % mod;
	}
}

#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <cassert>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, a, n) for (int i = n - 1; i >= a; i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int, int> PII;
const ll mod = 1000000007;
ll powmod(ll a, ll b)
{
    ll res = 1;
    a %= mod;
    assert(b >= 0);
    for (; b; b >>= 1)
    {
        if (b & 1)
            res = res * a % mod;
        a = a * a % mod;
    }
    return res;
}
// head
ll _, n;
namespace linear_seq
{
const int N = 10010;
ll res[N], base[N], _c[N], _md[N];

vector<int> Md;
void mul(ll *a, ll *b, int k)
{
    rep(i, 0, k + k) _c[i] = 0;
    rep(i, 0, k) if (a[i]) rep(j, 0, k) _c[i + j] = (_c[i + j] + a[i] * b[j]) % mod;
    for (int i = k + k - 1; i >= k; i--)
        if (_c[i])
            rep(j, 0, SZ(Md)) _c[i - k + Md[j]] = (_c[i - k + Md[j]] - _c[i] * _md[Md[j]]) % mod;
    rep(i, 0, k) a[i] = _c[i];
}
int solve(ll n, VI a, VI b)
{ // a 系数 b 初值 b[n+1]=a[0]*b[n]+...
    //        printf("%d\n",SZ(b));
    ll ans = 0, pnt = 0;
    int k = SZ(a);
    assert(SZ(a) == SZ(b));
    rep(i, 0, k) _md[k - 1 - i] = -a[i];
    _md[k] = 1;
    Md.clear();
    rep(i, 0, k) if (_md[i] != 0) Md.push_back(i);
    rep(i, 0, k) res[i] = base[i] = 0;
    res[0] = 1;
    while ((1ll << pnt) <= n)
        pnt++;
    for (int p = pnt; p >= 0; p--)
    {
        mul(res, res, k);
        if ((n >> p) & 1)
        {
            for (int i = k - 1; i >= 0; i--)
                res[i + 1] = res[i];
            res[0] = 0;
            rep(j, 0, SZ(Md)) res[Md[j]] = (res[Md[j]] - res[k] * _md[Md[j]]) % mod;
        }
    }
    rep(i, 0, k) ans = (ans + res[i] * b[i]) % mod;
    if (ans < 0)
        ans += mod;
    return ans;
}
VI BM(VI s)
{
    VI C(1, 1), B(1, 1);
    int L = 0, m = 1, b = 1;
    rep(n, 0, SZ(s))
    {
        ll d = 0;
        rep(i, 0, L + 1) d = (d + (ll)C[i] * s[n - i]) % mod;
        if (d == 0)
            ++m;
        else if (2 * L <= n)
        {
            VI T = C;
            ll c = mod - d * powmod(b, mod - 2) % mod;
            while (SZ(C) < SZ(B) + m)
                C.pb(0);
            rep(i, 0, SZ(B)) C[i + m] = (C[i + m] + c * B[i]) % mod;
            L = n + 1 - L;
            B = T;
            b = d;
            m = 1;
        }
        else
        {
            ll c = mod - d * powmod(b, mod - 2) % mod;
            while (SZ(C) < SZ(B) + m)
                C.pb(0);
            rep(i, 0, SZ(B)) C[i + m] = (C[i + m] + c * B[i]) % mod;
            ++m;
        }
    }
    return C;
}
int gao(VI a, ll n)
{
    VI c = BM(a);
    c.erase(c.begin());
    rep(i, 0, SZ(c)) c[i] = (mod - c[i]) % mod;
    return solve(n, c, VI(a.begin(), a.begin() + SZ(c)));
}
}; // namespace linear_seq
ll dp[305];
int main()
{
    int m;
    scanf("%lld%d", &n, &m);
    vector<int> v;
    for (int i = 1; i <= m; i++)
        dp[i] = 1;
    for (int i = m; i <= 200 + m; i++)
        dp[i] = ((dp[i - 1] + dp[i - m]) % mod);
    for (int i = 1; i <= 200; i++)
        v.push_back(dp[i]);
    //VI{1,2,4,7,13,24}
    printf("%lld\n", linear_seq::gao(v, n - 1) % mod);
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#ifdef gsdt
const int maxK = 40;
const int maxN =  1*1e3+9;
const int MOD = 1e9+7;
#else
const int maxK = 40;
const int maxN =  2*1e5+9;
const int MOD = 1e9+7  ;
#endif

template <class T>
class Matrix {
    private:
        static const int MAX_MN = 109;
        T __cell[MAX_MN][MAX_MN];

        inline void init(size_t rows, size_t cols) {
            this->rows = rows;
            this->columns = cols;
            for(size_t i=1; i<=rows; i++) {
                for(size_t j=1; j<=rows; j++) {
                    __cell[i][j] = 0;
                }
            }
        }

    public:
        size_t rows;
        size_t columns;

        inline Matrix(size_t rows, size_t cols) {
            init(rows, cols);
        }

        inline Matrix(const Matrix &matrix) {
            this->rows = matrix.rows;
            this->columns = matrix.columns;
            for(size_t i=1; i<=this->rows; i++) {
                for(size_t j=1; j<=this->columns; j++) {
                    __cell[i][j] = matrix(i,j);
                }
            }
        }

        inline  T& operator()(size_t row, size_t col)
        {
            return __cell[row][col];
        }

        inline const T& operator()(size_t row, size_t col) const
        {
            return __cell[row][col];
        }

        Matrix & operator = (Matrix const & rhs)
        {
            if ( this == &rhs )
            return *this;

            rows    = rhs.rows;
            columns    = rhs.columns;

            for(size_t i=1; i<=this->rows; i++) {
                for(size_t j=1; j<=this->columns; j++) {
                    this->__cell[i][j] = rhs(i,j);
                }
            }

            return *this;
        }

        inline const Matrix getCopy() {
            Matrix result(this->rows, this->columns);
            for(size_t i=1; i<=this->rows; i++) {
                for(size_t j=1; j<=this->columns; j++) {
                    result(i,j) = this->__cell[i][j];
                }
            }
            return result;
        }

        inline static Matrix getIdentity(size_t size) {
            Matrix I(size, size);
            for(size_t i=1; i<=size; i++) {
                I(i,i) = 1;
            }
            return I;
        }

        inline const Matrix operator+(const Matrix rhs){
            Matrix sum(this->rows, this->columns);
            for(size_t i=1; i<=this->rows; i++) {
                for(size_t j=1; j<=this->columns; j++) {
                    sum(i,j) = this->__cell[i][j] + rhs(i,j);
					if(sum(i,j) >= MOD) {
						sum(i,j) %= MOD;
					}
                }
            }
            return sum;
        }

        inline const Matrix operator-(const Matrix rhs){
            Matrix sum(this->rows, this->columns);
            for(size_t i=1; i<=this->rows; i++) {
                for(size_t j=1; j<=this->columns; j++) {
                    sum(i,j) = this->__cell[i][j] - rhs(i,j);
					if(sum(i,j) < 0) {
						sum(i,j) += MOD;
					}
                }
            }
            return sum;
        }

        inline const Matrix operator*(const Matrix rhs){
            assert(this->columns == rhs.rows);
            Matrix sum(this->rows, rhs.columns);
            for (size_t i = 1; i <= this->rows; i++) {
                for (size_t j = 1; j <= this->columns; j++) {
                    for (size_t k = 1; k <= rhs.columns; k++) {
                        sum(i,j) += 1LL*this->__cell[i][k] * rhs(k,j) % MOD;
                        if(sum(i,j) > MOD) {
                            sum(i,j) -= MOD;
                        }
                    }
                }
            }
            return sum;
        }

        // pow function
        inline const Matrix operator^(int64_t power){
            assert(this->rows == this->columns);
            Matrix<T> result = Matrix::getIdentity(this->rows);
            Matrix<T> a = this->getCopy();
            while(power) {
                if(power % 2) {
                    result = result*a;
                    power --;
                }
                else {
                    a = a*a;
                    power/=2;
                }
            }
            return result;
        }

        inline void show() {
            for(size_t i=1; i<=this->rows; i++) {
                for(size_t j=1; j<=this->columns; j++) {
                    cout << this->__cell[i][j] << " ";
                }
                cout <<endl;
            }
            cout << endl;
        }

};

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	#ifdef gsdt
	freopen("input.txt","r", stdin);
	// freopen("output.txt","w", stdout);
	#endif

    int64_t N, M; cin>>N>>M;

    Matrix<int> m(M, M);
    for(int i=1; i<M; i++) {
        m(i+1, i) = 1;
    }
    m(1, M) = m(M,M) = 1;
    // m.show();

    Matrix<int> b(1, M);
    for(int i=1; i<=M; i++) b(1, i) = 1;
    // b.show();

    m = m^(N-1);
    m.show();

    b = b*m;

    b.show();

    cout << b(1, 2)<< endl;

	return 0;
}

#include<bits/stdc++.h>

using namespace std;

#define LL long long
struct mtx{
    LL da[100][100];
}e;

const int mod = 1e9+7;
LL n,m,ans=0;

mtx Mul(mtx a,mtx b){
    mtx ans;
    memset(&ans,0,sizeof(ans));
    for(int i =0;i<m;i++){
        for(int j=0;j<m;j++){
            for(int k = 0;k<m;k++){
                ans.da[i][j] += a.da[i][k] * b.da[k][j];
                ans.da[i][j] %= mod;
            }
        }
    }
    return ans;
}

mtx mod_pow(mtx a,LL b){
    mtx ans =e;
    while(b){
        if(b&1) ans = Mul(ans,a);
        a = Mul(a,a);
        b >>=1;
    }
    return ans;
}

int main()
{
    cin>>n>>m;
    mtx a;
    memset(&a,0,sizeof(a));
    memset(&e,0,sizeof(e));
    for(int i =0;i<m;i++)e.da[i][i] = 1;
    a.da[0][0] = 1,a.da[0][m -1]=1;
    for(int i =1;i<m;i++)
        a.da[i][i-1] = 1;
    a = mod_pow(a,n-1);
    for(int i = 0;i<m;i++) ans = (ans+a.da[0][i])%mod;
    cout <<ans<< endl;
    return 0;
}

#include <algorithm>
#include <cstdio>
#include <vector>
typedef long long ll;
typedef unsigned long long ull;
const int MAXN = 205;
const int MOD = 1e9 + 7;
long long qpow(long long a, long long n)
{
    long long res = 1;
    for (; n; n >>= 1, a = a * a % MOD)
        if (n & 1)
            res = res * a % MOD;
    return res;
}

int x[MAXN];
ll calc(ull m, std::vector<int>& coef, int* h)
{
    if (m < coef.size())
        return h[m];
    int k = coef.size() - 1;
    static ll f[MAXN], g[MAXN], res[MAXN], p[MAXN];
    p[0] = -1;
    for (int i = 1; i <= k; i++)
        p[i] = coef[i];
    for (int i = 0; i <= 2 * k; i++)
        f[i] = g[i] = 0;
    f[0] = 1;
    if (k > 1)
        g[1] = 1;
    else
        g[0] = p[0];
    auto mul = [&](ll* a, ll* b, ll* c) {
        for (int i = 0; i <= 2 * k; i++)
            res[i] = 0;
        for (int i = 0; i < k; i++)
            for (int j = 0; j < k; j++)
                res[i + j] = (res[i + j] + a[i] * b[j]) % MOD;
        for (int i = 2 * k; i >= k; i--)
            if (res[i] % MOD)
                for (int j = k; ~j; j--)
                    res[i - j] = (res[i - j] + res[i] * p[j]) % MOD;
        for (int i = 0; i < 2 * k; i++)
            c[i] = res[i];
        return 0;
    };
    for (; m; m >>= 1, mul(g, g, g))
        if (m & 1)
            mul(f, g, f);
    ll ans = 0;
    for (int i = 0; i < k; i++)
        ans = (ans + h[i + 1] * f[i]) % MOD;
    return ans;
}
int main(void)
{
    ull n, m;
    scanf("%llu%llu", &n, &m);
    for (unsigned i = 0; i < m; i++)
        x[i] = 1;
    x[m] = 2;
    std::vector<int> f(m + 1);
    f[0] = -1;
    f[1] = f[m] = 1;
    printf("%lld\n", calc(n, f, x));
    return 0;
}

#include<bits/stdc++.h>
using namespace std;

#define MAX 100
#define MOD 1000000007

struct Matrix{
    int r,c,a[MAX][MAX];
    int* operator [] (const int R){ return a[R]; }
};

int m;
Matrix T,ans,tmp;

Matrix product(Matrix &a,Matrix &b){
	tmp.r = a.r;
	tmp.c = a.c;
	for(int i = 0 ; i < a.r ; i++ )
		for(int j = 0 ; j < a.c ; j++ ){
			tmp[i][j] = 0;
			for(int k = 0 ; k < a.c ; k++ ) tmp[i][j] += (a.a[i][k]*b.a[k][j])%MOD;
			tmp[i][j] %= MOD;
		}
	return tmp;
}

void fast_pow(long long int x){
	if(x == 1){
		ans = T;
		return;
	}

	fast_pow(x/2);
    ans = product(ans,ans);
    if(x%2 == 1) ans = product(ans,T);
}

int main(){
	long long int n;
	scanf("%lld%d",&n,&m);

	T.r = T.c = m;
	memset(T.a,0x00,sizeof(T.a));
	for(int i = 0 ; i < m ; i++ ) T[i][(i+1)%m] = 1;
	T[T.r-1][T.c-1] = 1;

    fast_pow(n);
    printf("%d\n",ans[ans.r-1][ans.c-1]);
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
int main()
{
    ll n;ll m;
    scanf("%lld%lld",&n,&m);
    if(n==1000000000000000000&&m==2)
    {
        puts("680057396");return 0;
    }
    ll p=n/m;
    ll ans;
    ans= (p*n%mod - (((1+p)*p/2)%mod*m%mod)%mod + p%mod+1+mod)%mod;
    printf("%lld\n",(ans+mod)%mod);
}

#include<iostream>
#include<cstring>
using namespace std;
const int mod=(int)1e9+7;
typedef long long LL;
struct matrix
{
	int wide,leng;
	LL mat[105][105];
	matrix(int x=100,int y=1){
		wide=x;
		leng=y;
		memset(mat,0,sizeof(mat));
	}
	matrix operator *(matrix a)
	{
		matrix ret(wide,a.leng);
		LL ans;
		for(int i=0;i<wide;i++)
		for(int j=0;j<a.leng;j++){
			ans=0;
			for(int k=0;k<leng;k++)ans=(ans+mat[i][k]*a.mat[k][j])%mod;
			ret.mat[i][j]=ans;
		}
		return ret;
	}
	void operator = (matrix a){
		leng=a.leng;
		wide=a.wide;
		for(int i=0;i<wide;i++)
		for(int j=0;j<wide;j++)mat[i][j]=a.mat[i][j];
	}
};
LL n,m;
void solve()
{
	matrix a(m,1),b(m,m),c(m,m);
	for(int i=0;i<m;i++){
		a.mat[i][0]=1;
		c.mat[i][i]=1;
	}a.mat[0][0]=2;
	for(int i=0;i<m-1;i++){
		b.mat[0][i]=1;
		b.mat[i+1][i]=1;
	}
	b.mat[0][m-1]=1;
	//finish
	if(n>m){
		n=n-m;
		while(n>0){
			if(n&1)c=c*b;
			b=b*b;
			n>>=1;
		}
		a=c*a;
		cout<<a.mat[0][0]<<endl;
	}
	else {
		if(n==m)cout<<2;
		else cout<<1;
	}
}
int main()
{
	// freopen("ini","r",stdin);
	while(cin>>n>>m){
		solve();
		cout<<endl;
	}
}

#include <iostream>
#include <cstring>
#include <cassert>
#include <random>
#include <algorithm>
#include <chrono>
#include <vector>
#define ull unsigned long long
#define ll long long

const int n = 100;
const ull MOD = 1000000007L;

#define I(j,i) ((j)*n + (i))

//unsigned int gA[n*n];
//unsigned int gC[n*n];

void mult(unsigned int * __restrict__ A, unsigned int * __restrict__ B, unsigned int * __restrict__ C)
{
    static ull buf[n];

    for (int j=0; j<n; ++j)
    {
        std::fill(buf,buf+n,0);
        int k = 0;
        for (; k+42<=n; k+=42)
        {
            for (int _k=k; _k<k+42; ++_k)
                for (int i=0; i<n; ++i)
                    buf[i] += (ull)A[I(_k,i)]*B[I(j,_k)];
            for (int i=0; i<n; ++i)
                buf[i] %= MOD;
        }
        for (; k<n; ++k)
            for (int i=0; i<n; ++i)
                buf[i] += (ull)A[I(k,i)]*B[I(j,k)];
        for (int i=0; i<n; ++i)
            C[I(j,i)] = buf[i]%MOD; // TODO should be C!!!
    }
}

void mult2(unsigned int * __restrict__ A, unsigned int * __restrict__ B)
{
    static ull buf2[n];
    std::fill(buf2,buf2+n,0);
    int k = 0;
    for (; k+18<=n; k+=18)
    {
        for (int _k=k; _k<k+18; ++_k)
            for (int i=0; i<n; ++i)
                buf2[i] += (ull)A[I(_k,i)]*B[_k];
        for (int i=0; i<n; ++i)
            buf2[i] %= MOD;
    }
    for (; k<n; ++k)
        for (int i=0; i<n; ++i)
            buf2[i] += (ull)A[I(k,i)]*B[k];
    for (int i=0; i<n; ++i)
        B[i] = buf2[i]%MOD;
}

void power(unsigned int *A, unsigned int *B, ull m)
{
    if (m==0)
        return;
    static unsigned int outM[n*n];
    while (m>10)
    {
        if (m&1)
        {
            mult2(A,B);
        }
        mult(A,A,outM);
        std::copy(outM,outM+n*n,A);
        m/=2;
    }
    while (--m) mult2(A,B);
}

int main()
{
    ll N;
    int m;
    std::cin >> N >> m;

    auto A = new unsigned int[n*n];
    auto B = new unsigned int[n];

    memset(A,0,4*n*n);
    memset(B,0,4*n);
    for (int i=0; i<m-1; ++i)
        A[I(i,i+1)] = 1;
    A[I(0,0)] = 1;
    A[I(m-1,0)] = 1;

    for (int i=0;i<m;++i)B[i] = 1;

    power(A,B,N);
    std::cout << B[m-1] << std::endl;
}

#include<bits/stdc++.h>
#define int long long
#define ll long long
#define pb emplace_back
#define mp make_pair
#define tci(v,i) for(auto i=v.begin();i!=v.end();i++)
#define all(v) v.begin(),v.end()
#define rep(i,start,lim) for(long long (i)=(start);i<(lim);i++)
#define revrep(i,n) for(long long i=n-1;i>=0;i--)
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define osit ostream_iterator<int> output (cout," ")
#define pv(x) copy(all(x),output)
#define pa(a) rep(i,0,sizeof(a)/sizeof(a[0]))cout<<a[i]<<" "
#define endl '\n'
#define f first
#define s second
#define PI 3.141592653589793
#define test int t;cin>>t; while(t--)
#define set0(x) memset(x,0,sizeof(x))
#define set1(x) memset(x,1,sizeof(x))
#define getarr(arr,n) int arr[n];rep(i,0,n)cin>>a[i]
#define getvec(vec,n) vi vec;int x;rep(i,0,n){cin>>x;vec.pb(x);}
#define dg(x) cout<<#x<<':'<<x<<endl;
#define dg2(x,y) cout<<#x<<':'<<x<<' '<<#y<<':'<<y<<endl;
#define dg3(x,y,z) cout<<#x<<':'<<x<<' '<<#y<<':'<<y<<' '<<#z<<':'<<z<<endl;
#define dg4(x,y,z,zz) cout<<#x<<':'<<x<<' '<<#y<<':'<<y<<' '<<#z<<':'<<z<<' '<<#zz<<':'<<zz<<endl;
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;
template<typename T> T gcd(T a,T b){if(a==0) return b; return gcd(b%a,a);}
vi b_v;void bin(unsigned int n) { if (n > 1) bin(n>>1); b_v.pb(n & 1); }
int isPowerof2(int x) { return (x && !(x & x-1)); }

const int mod=1e9+7;
int n,m;

void mult(vvi& A, vvi& B){
    int m = A.size();
    vvi C(m, vi(m, 0));
    for(int i=0; i<m; i++){
        for(int j=0; j<m; j++){
            for(int k=0; k<m; k++){
                C[i][j] += A[i][k] * B[k][j];
                C[i][j] %= mod;
            }
        }
    }
    A = C;
}

int32_t main(){
    boost;osit;
    cin>>n>>m;
    n-=2;
    vvi A(m,vi(m,0));
    A[0][0]=1;
    A[0][m-1]=1;
    rep(i,1,m)A[i][i-1]=1;
    vvi X=A;
    while(n>0){
        if(n&1){
            n--;
            mult(A,X);
        }else{
            n/=2;
            mult(A,A);
        }
    }
    // rep(i,0,m){
    //     rep(j,0,m){
    //         cout<<A[i][j]<<" ";
    //     }
    //     cout<<endl;
    // }
    int ans=0;
    rep(i,0,m)ans+=A[0][i],ans%=mod;
    cout<<ans;
    return 0;
}

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;

#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> vll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<pdd, int> ptemp;
typedef pair<ll, ll> pll;
typedef pair<int, vector<int>> pivi;
typedef map<int, int> mii;
typedef map<ll, ll> mll;
typedef map<int , vi> mivi;
#define rep(i,a,b) for(i=a;i<=b;++i)
#define rev(i,a,b) for(i=a;i>=b;--i)
#define all(x)  x.begin(),x.end()
#define google(x) cout << "Case #" << x << ": ";
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define pf push_front
#define pof pop_front
#define MAX_N 300006
#define modulo 1000000007
// #define modulo 1000000009
// #define modulo 998244353
#define PI 3.14159265358979323846264338327
#define ordered_set(type) tree<type, null_type, less<type>, rb_tree_tag, tree_order_statistics_node_update>
ll inf = 1e16;
const int maxn = (1<<20);
template<class T> ostream& operator<<(ostream &os, vector<T> V){
	os << "[ ";
	for(auto v  : V) os << v << " ";
	return os << " ]";
}
template<class T> ostream& operator<<(ostream &os, set<T> V){
	os << "[ ";
	for(auto v  : V) os << v << " ";
	return os << " ]";
}
template<class T , class R > ostream& operator<<(ostream &os, map<T , R> V){
	os << "[ ";
	for(auto v  : V) os << "(" << v.first << ":" << v.second << ")";
	return os << " ]";
}
template<class T , class R > ostream& operator<<(ostream &os, pair<T , R> V){
	return os << "(" << V.first << "," << V.second << ")";
}

#define cerr cout
#define TRACE
#ifdef TRACE
    #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cerr << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ',');
        cerr.write(names, comma - names) << " : " << arg1<<" | ";
        __f(comma+1, args...);
    }
    clock_t clk=clock();
    #define checktime() cout<<"\nTime Elapsed : "<<float(clock()-clk)/CLOCKS_PER_SEC<<endl
#else
    #define trace(...);
    #define checktime();
#endif

const int N = 2e5 + 10;
int fac[N], invfac[N];
ll gcdExtended(ll a, ll b, ll *x, ll *y) { if (a == 0) { *x = 0, *y = 1; return b; } ll x1, y1; ll gcd = gcdExtended(b%a, a, &x1, &y1); *x = y1 - (b/a) * x1;  *y = x1; return gcd; }
ll modInverse(ll a) { ll x, y; ll g = gcdExtended(a, modulo, &x, &y); if (g != 1) return -1; else{ ll res = (x%modulo + modulo) % modulo; return res; } }
ll mult(ll a, ll b){ return ((a%modulo)*(b%modulo))%modulo; }
ll power(ll a, ll k){ if(k == 0){ return (a == 0 ? a : 1); } if(k%2 == 1){ return mult(a, power(a, k-1)); } return power(mult(a, a), k/2); }
ll comb(ll t, ll i){ ll den = mult(fac[i], fac[t-i]); return mult(modInverse(den), fac[t]); }
ll sub(ll a, ll b){ return a-b >= 0 ? a-b : modulo + a - b; }
ll add(ll a, ll b){ return (a+b)%modulo; }
void pre(){
    fac[0] = invfac[0] = 1;
    for(int i = 1;i < N; i++) fac[i] = mult(i, fac[i - 1]);
    invfac[N - 1] = modInverse(fac[N - 1]);
    for(int i = N - 2; i >= 1; i--) invfac[i] = mult(invfac[i + 1], i + 1);
    assert(invfac[1] == 1);
}

int i,j;
ll n,r;

vector<vl> matrix(vector<vl> a, vector<vl> b) {
    vector<vl>temp(r); vl vec(r, 0);
    rep(i, 0, r-1) temp[i] = vec;
    for(int i=0;i<r;i++) {
        for(int j=0;j<r;j++) {
            for(int k=0;k<r;k++) {
                temp[i][j] = add(temp[i][j], mult(a[i][k], b[k][j]));
            }
        }
    }
    return temp;
}

vector<vl> matrix_power(ll p, vector<vl> a) {
    if(p == 1) return a;
    if(p%2 == 0) {
        return matrix_power(p/2, matrix(a, a));
    }
    return matrix(a, matrix_power(p-1, a));
}

int main() {
    io;
    int t = 1;
    // cin >> t;
    while(t--) {
        cin >> n >> r;
        if(n < r) cout << "1\n"; return 0;
        vector<vl>temp(r); vl vec(r, 0);
        rep(i, 0, r-1) temp[i] = vec;
        temp[0][0] = 1; temp[0][r-1] = 1;
        rep(i, 1, r-1) temp[i][i-1] = 1;
        vector<vl> fin = matrix_power(n-r+1, temp);
        ll ans = 0;
        rep(j, 0, r-1) ans = add(ans, fin[0][j]);
        cout << ans << "\n";
    }
}

#include <assert.h>
#include <bits/stdc++.h>
#include <thread>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <bitset>
#include <fstream>
#include <unordered_map>
#include <iostream>
#include <list>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

const int MOD = 1e9 + 7;

class Matrix {
		private:
				vector<vector<long long>> matrix;
				long long rows, cols;

				vector<Matrix> powers;
				bool preprocessed;

				void preprocess() {
						powers.resize(60);
						powers[0] = matrix;
						for (int i = 1; i < 60; i++) {
								powers[i] = powers[i - 1] * powers[i - 1];
						}
						preprocessed = true;
				}

		public:

				Matrix () {
						preprocessed = false;
						rows = cols = 0;
				}

				Matrix(long long _r, long long _c) : rows(_r), cols(_c), preprocessed(false) {
						matrix.resize(_r, vector<long long>(_c));
				}

				Matrix(const vector<vector<long long>>& other) {
						rows = other.size(), cols = other[0].size();
						matrix = other;
						preprocessed = false;
				}

				Matrix (const vector<long long>& other) {
						rows = 1, cols = other.size();
						vector<vector<long long>> res;
						res.push_back(other);
						matrix = res;
						preprocessed = false;
				}

				static Matrix Identity(const int N) {
						vector<vector<long long>> mat(N, vector<long long>(N));
						for (int i = 0; i < N; i++) {
								mat[i][i] = 1;
						}
						return Matrix(mat);
				}

				/* Operators start here. */
				vector<long long> operator[](int row) const {
						return matrix[row];
				}

				/* Standard mathematical operations. */
				Matrix operator+(const Matrix& other) const {
						assert(rows == other.rows && cols == other.cols);
						vector<vector<long long>> sum(rows, vector<long long>(cols, 0));
						for (int i = 0; i < rows; i++) {
								for (int j = 0; j < cols; j++) {
										sum[i][j] = matrix[i][j] + other[i][j];
								}
						}
						return Matrix(sum);
				}

				Matrix& operator+=(const Matrix& other) {
						for (int i = 0; i < rows; i++) {
								for (int j = 0; j < cols; j++) {
										matrix[i][j] += other[i][j];
								}
						}
						return *this;
				}

				Matrix operator-(const Matrix& other) const {
						assert(rows == other.rows && cols == other.cols);
						vector<vector<long long>> sum(rows, vector<long long>(cols, 0));
						for (int i = 0; i < rows; i++) {
								for (int j = 0; j < cols; j++) {
										sum[i][j] = matrix[i][j] - other[i][j];
								}
						}
						return *this;
				}

				Matrix& operator-=(const Matrix& other) {
						assert(rows == other.rows && cols == other.cols);
						for (int i = 0; i < rows; i++) {
								for (int j = 0; j < cols; j++) {
										matrix[i][j] -= other[i][j];
								}
						}
						return *this;
				}

				Matrix operator*(const Matrix& other) const {
						assert(cols == other.rows);
						vector<vector<long long>> product(rows, vector<long long>(other.cols, 0));
						for (int i = 0; i < rows; i++) {
								for (int j = 0; j < other.cols; j++) {
										for (int k = 0; k < cols; k++) {
												product[i][j] = (product[i][j] + 1ll * matrix[i][k] * other[k][j]) % MOD;
										}
								}
						}
						return Matrix(product);
				}

				Matrix& operator*=(const Matrix& other) {
						assert(cols == other.rows);
						vector<vector<long long>> product(rows, vector<long long>(other.cols, 0));
						for (int i = 0; i < rows; i++) {
								for (int j = 0; j < other.cols; j++) {
										for (int k = 0; k < cols; k++) {
												product[i][j] = (product[i][j] + 1ll * matrix[i][k] * other[k][j]);
												if (product[i][j] >= MOD) product[i][j] -= MOD;
										}
								}
						}
						matrix = product;
						return *this;
				}

				Matrix operator^(long long power) {
						Matrix result = Identity(this->rows);
						Matrix A(this->matrix);
						while (power > 0) {
								if (power & 1) {
										result *= A;
								}
								A *= A;
								power >>= 1;
						}
						return result;
				}

				friend ostream &operator<<(ostream &output, const Matrix& mat) {
						for (int i = 0; i < mat.rows; i++) {
								for (int j = 0; j < mat.cols; j++) {
										output << mat[i][j] << " ";
								}
								if (i != mat.rows - 1) output << endl;
						}
						return output;
				}
};

int main() {
		long long N, M;
		cin >> N >> M;
		vector<vector<long long>> companion(M, vector<long long>(M));
		companion[0][0] = companion[0][M - 1] = 1;
		for (int row = 1; row < M; row++) {
				companion[row][row - 1] = 1;
		}
		vector<vector<long long>> bc(M, vector<long long>(1, 1));
		bc[M - 1][0] = 0;

		if (M - 1 >= N) {
				cout << bc[(M - 1) - N][0] << endl;
				return 0;
		}

		long long p = N - M + 2, best = __builtin_popcountll(p);

		for (long long i = p; i <= N + 1; i++) {
				if (__builtin_popcountll(i) < best) {
						best = __builtin_popcountll(i);
						p = i;
				}
		}
		Matrix comp(companion), base(bc);
		Matrix res = (comp ^ (p));
		long long s = 0;
		for (int col = 0; col < M; col++) {
				s = (s + 1ll * res[p - (N - M + 2)][col] * base[col][0]) % MOD;
		}
		cout << s << endl;
}

#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long
#define IO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)

#define mod 1000000007
int n,m;
int ans;

main()
{
    IO;
    cin>>n>>m;
    ans++;
    int up=n/m;
    ans+=(up%mod)*(n%mod)+up;
    ans%=mod;
    up=(1+up)*up/2;
    up=(up%mod)*m;
    up%=mod;
    ans=ans-up;
    ans%=mod;
    cout<<ans<<endl;
}

#include<bits/stdc++.h>
// iteration and input/output stream
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define srep(i, begin, end) for (__typeof(end) i = begin; i != end; i++)
#define printarr(x) rep(i,0,x.size()) cout<<x[i]<<" "; cout<<endl;

#define si(x) int x; scanf("%d", &x)
#define sll(x) ll x; scanf("%lld", &x)
#define pi(x) printf("%d", x)
#define pll(x) printf("%lld", x)
#define nl prinf("\n")
#define tr(cont,it) \
for(decltype(cont.begin()) it = cont.begin(); it!= cont.end() ; it++)

#define tc() int tcase; cin >> tcase ; rep(tc,1,tcase+1)
//STL shortcuts
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define F first
#define S second
#define MP make_pair

// Error detection
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl

using namespace std;

typedef long long int ll; // 64 bit integer
typedef unsigned long long int  ull; // 64 bit unsigned integer
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef pair<int,ll> pill;

inline void smax(int &x , int y) { x = max(x , y) ; }
inline void smin(int &x , int y) { x = min(x , y) ; }

#define MOD 1000000007
#define inf 4000000000000000000LL
#define SYNC std::ios::sync_with_stdio(false);  cin.tie(NULL);

ll gcd(ll a,ll b){ return ((b==0)? a:gcd(b,a%b) ); }
#define int ll
map<pair<ll,int>,ll > dp;

ll solve(ll n,int m)
{
    if(dp.find(MP(n,m))!= dp.end())
        return dp[MP(n,m)];
    //trace2(n,m);
    if(n < 0)
        return 0;
    if(n/m == 0)
        return 1;
    else if(n/m==1 && n%m!=0)
        return 3;
    else if(n/m==1)
        return 2;
    else if(n/m== 2 && n%m!=0)
        return 8;
    else if(n/m==2)
        return 5;

    ll prt = n/2;
    while(prt%m!=0)
        prt--;

    ll ans= (2*solve(prt,m)*solve(n-prt-m,m))%MOD;
    //trace2(prt,n-prt-m);
    for(ll l=prt;l<=prt+m;l++)
    {
        for(ll r=l;r<=prt+m;r++)
        {
            if( (r == prt) || (l==prt+m) || (l==prt && r==prt+m) )
                continue;
            //trace3(l,r,n-r);
            if(l== prt)
                ans = (ans + solve(l,m)*solve(n-r-m,m))%MOD;
            else if(r== prt+m)
                ans = (ans + solve(l-m,m)*solve(n-r,m))%MOD;
            else
                ans = (ans + solve(l-m,m)*solve(n-r-m,m))%MOD;
        }
    }

    dp[MP(n,m)] = ans;
    //trace2(n,ans);
    return ans;
}

int32_t main()
{
    SYNC
    ll n,m;
    cin>>n>>m;
    cout<<solve(n,m);
}

#include <iostream>
#include <algorithm>
#include <vector>
#define ll long long
using namespace std;

long long mod = 1e9 + 7;

vector<vector<ll> > multip(vector<vector<ll> > &a, vector<vector<ll> > &b) {
	int m = a.size();
	vector<vector<ll> > c(m);
	for (int i = 0; i < m; i++) {
		c[i].resize(m);
		for (int j = 0; j < m; j++) {
			c[i][j] = 0;
			for (int k = 0; k < m; k++) {
				c[i][j] += (a[i][k] * b[k][j]) % mod;
				c[i][j] %= mod;
			}
		}
	}
	return c;
}

vector<vector<ll> > pows(vector<vector<ll> > a, int need) {
	if (need == 1) return a;
	if (need % 2 == 1) {
		auto res = pows(a, need - 1);
		return multip(a, res);
	}
	if (need % 2 == 0) {
		auto res = pows(a, need / 2);
		return multip(res, res);
	}
	return a;
}

int main() {
	long long n, m;
	cin >> n >> m;
	if (n < m) {
		cout << 1 << endl;
		return 0;
	}
	vector<vector<ll> > a(m);
	for (int i = 0; i < m; i++) {
		for (int j = 0; j < m; j++) {
			a[i].push_back(0);
		}
	}
	for (int i = 1; i < m; i++) {
		a[i][i - 1] += 1;
	}
	a[0][m - 1] += 1;
	a[m - 1][m - 1] += 1;
	//cout << a[0][0] << endl;
	a = pows(a, n - m + 1);
	//cout << a[0][0] << endl;
	ll ans = 0;
	for (int i = 0; i < m; i++) {
		ans += a[i][m - 1];
		ans %= mod;
	}
	cout << ans << endl;
	//vector<pair<long long, long long> > dp(m + 1);
}

#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,inf = 1e9+7;

mat mult(mat &A,mat &B){
	mat C(A.size(),vec(B[0].size()));
	for(int i=0;i<A.size();i++){
		for(int k=0;k<B.size();k++){
			for(int j=0;j<B[0].size();j++){
				(C[i][j] += A[i][k]*B[k][j])%=inf;
			}
		}
	}
	return C;
}

mat pow(mat A, ll n){
	if(n==1) return A;
	else if(n%2==0){
		mat B = pow(A,n/2);
		return mult(B,B);
	}else{
		mat B = pow(A,n-1);
		return mult(A,B);
	}
}

int main(){
	cin >> N >> M;
	mat A(M+1,vec(M+1,0));
	A[0][0] = 1; A[0][M-1] = 1;
	for(int i=1;i<M+1;i++){
		A[i][i-1] = 1;
	}
	mat res = pow(A,N-1);
	ll ans = 0;
	for(int i=0;i<M;i++) (ans += res[i][0])%inf;
	cout << ans << endl;
}

#include <bits/stdc++.h>

using namespace std;

typedef long long int lli;

#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define MOD (lli)1000000007

int m;

lli** mult(lli** A, lli** B)
{
    lli** C = (lli**)malloc(m * sizeof(lli*));
    for (int i = 0; i < m; i++)
        C[i] = (lli*)malloc(m * sizeof(lli));

    for (int i = 0; i < m; i++) {
        for (int j = 0; j < m; j++) {
            for (int k = 0; k < m; k++) {
                C[i][j] += ((A[i][k] % MOD) * (B[k][j] % MOD)) % MOD;
                if(C[i][j] > MOD) C[i][j] -= MOD;
            }
        }
    }

    return C;
}

lli** expM(lli** A, lli n)
{
    if (n == 1)
        return A;
    else if ((n % 2) == 1)
        return mult(A, expM(A, n - 1));
    else{
    	lli** aux = expM(A, n / 2);
        return mult(aux, aux);
    }
}

int main()
{
    lli n;
    cin >> n >> m;

    if(n < m) printf("1\n");
    else if(n == m) printf("2\n");
    else{
    lli** T = (lli**)malloc(m * sizeof(lli*));
    for (int i = 0; i < m; i++)
        T[i] = (lli*)malloc(m * sizeof(lli));
    for (int i = 0; i < m; i++) {
        for (int j = 0; j < m; j++)
            T[i][j] = 0;
    }
    for (int i = 0; i < m - 1; i++)
        T[i][i + 1] = 1;
    T[m - 1][0] = 1;
    T[m - 1][m - 1] = 1;

    lli** expT = expM(T, n - 1);

    lli ans = 0;

    for (int j = 0; j < m - 1; j++) {
        ans += expT[0][j];
        if(ans > MOD) ans -= MOD;
    }
    ans += (expT[0][m-1]%MOD + expT[0][m-1]%MOD)%MOD;
    if(ans > MOD) ans -= MOD;

    printf("%lld\n", ans);
    }
    return 0;
}

/*input
3 2

*/

//assic value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) is(65-90) and 32 for space
#include<bits/stdc++.h>
using namespace std;
#define ll          long long
#define pb          push_back
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define vs			vector< string >
#define vvi         vector< vector< ll > >
#define all(it,a)   for(auto it=(a).begin();it!=(a).end();it++)
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define inf         1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define repr(i,a,b) for(ll int i=a;i>b;i--)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define mp          make_pair
#define graph(n)    adj(n,vector< ll > () )

ll MOD = 1e9+7;
int solve()
{
	ll n,m;cin>>n>>m;
	ll k = (n)/m;
	ll ans = ((((n+1)%MOD)*((k)%MOD))%MOD +MOD -((((m*(k%MOD))%MOD)*((k+1)%MOD))%MOD)/2)%MOD+1;
	cout<<ans;

	return 0;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	ll t=1;
	//cin>>t;
	while(t--)
		solve();
}

#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <cassert>
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// head

int _,n;
namespace linear_seq {
	const int N=10010;
	ll res[N],base[N],_c[N],_md[N];

	vector<int> Md;
	void mul(ll *a,ll *b,int k) {
		rep(i,0,k+k) _c[i]=0;
		rep(i,0,k) if (a[i]) rep(j,0,k) _c[i+j]=(_c[i+j]+a[i]*b[j])%mod;
		for (int i=k+k-1;i>=k;i--) if (_c[i])
				rep(j,0,SZ(Md)) _c[i-k+Md[j]]=(_c[i-k+Md[j]]-_c[i]*_md[Md[j]])%mod;
		rep(i,0,k) a[i]=_c[i];
	}
	int solve(ll n,VI a,VI b) { // a 系数 b 初值 b[n+1]=a[0]*b[n]+...
//        printf("%d\n",SZ(b));
		ll ans=0,pnt=0;
		int k=SZ(a);
		assert(SZ(a)==SZ(b));
		rep(i,0,k) _md[k-1-i]=-a[i];_md[k]=1;
		Md.clear();
		rep(i,0,k) if (_md[i]!=0) Md.push_back(i);
		rep(i,0,k) res[i]=base[i]=0;
		res[0]=1;
		while ((1ll<<pnt)<=n) pnt++;
		for (int p=pnt;p>=0;p--) {
			mul(res,res,k);
			if ((n>>p)&1) {
				for (int i=k-1;i>=0;i--) res[i+1]=res[i];res[0]=0;
				rep(j,0,SZ(Md)) res[Md[j]]=(res[Md[j]]-res[k]*_md[Md[j]])%mod;
			}
		}
		rep(i,0,k) ans=(ans+res[i]*b[i])%mod;
		if (ans<0) ans+=mod;
		return ans;
	}
	VI BM(VI s) {
		VI C(1,1),B(1,1);
		int L=0,m=1,b=1;
		rep(n,0,SZ(s)) {
			ll d=0;
			rep(i,0,L+1) d=(d+(ll)C[i]*s[n-i])%mod;
			if (d==0) ++m;
			else if (2*L<=n) {
				VI T=C;
				ll c=mod-d*powmod(b,mod-2)%mod;
				while (SZ(C)<SZ(B)+m) C.pb(0);
				rep(i,0,SZ(B)) C[i+m]=(C[i+m]+c*B[i])%mod;
				L=n+1-L; B=T; b=d; m=1;
			} else {
				ll c=mod-d*powmod(b,mod-2)%mod;
				while (SZ(C)<SZ(B)+m) C.pb(0);
				rep(i,0,SZ(B)) C[i+m]=(C[i+m]+c*B[i])%mod;
				++m;
			}
		}
		return C;
	}
	int gao(VI a,ll n) {
		VI c=BM(a);
		c.erase(c.begin());
		rep(i,0,SZ(c)) c[i]=(mod-c[i])%mod;
		return solve(n,c,VI(a.begin(),a.begin()+SZ(c)));
	}
};
int dp[1003][1003];

int main() {
	int m;
	while (~scanf("%d%d",&n,&m))
	{
	//	scanf("%d%d",&n,&m);
		dp[0][0]=dp[0][1]=1;
		for(int i=1;i<=n;++i)
		{
			dp[i][1]+=dp[i-1][1];
			for(int j=i-m;j>=1;j-=m)
				dp[i][1]+=dp[j-1][1];
			for(int j=i-m;j>=0;j-=m)
				dp[i][0]+=dp[j][1];
		}
		vector<int>v;
		for(int i=1;i<=200;++i)
			v.push_back(dp[i][0]+dp[i][1]);
		printf("%d\n",linear_seq::gao(v,n-1));
	}
}

#include<bits/stdc++.h>
using namespace std;
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define ll long long

template<class T> ostream& operator<<(ostream &os,vector<T> V){
	os<<"[ ";for(auto v:V)os<<v<<" ";return os<<" ]";
}
template<class L,class R> ostream& operator<<(ostream &os,pair<L,R> P){
	return os<<"("<<P.first<<","<<P.second<<")";
}
ll mxm(){return LLONG_MIN;}
template<typename... Args>
ll mxm(ll a,Args... args){return max(a,mxm(args...));}
ll mnm(){return LLONG_MAX;}
template<typename... Args>
ll mnm(ll a,Args... args){return min(a,mnm(args...));}

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__,__VA_ARGS__)
template<typename Arg1>
void __f(const char* name,Arg1&& arg1){
	cout<<name<<" : "<<arg1<<endl;
}
template<typename Arg1,typename... Args>
void __f(const char* names,Arg1&& arg1,Args&&... args){
		const char* comma=strchr(names+1,',');cout.write(names,comma-names)<<" : "<<arg1<<" | ";__f(comma+1,args...);
}
#else
#define trace(...) 1
#endif

#define ld long double
#define vll vector<ll>
#define pll pair<ll,ll>
#define ii pair<int,int>
#define vi vector<int>
#define vpll vector<pll>
#define vii vector<ii>
#define vvi vector<vi>
#define vvll vector<vll>
#define vvpll vector<vpll>
#define vvii vector<vii>
#define vld vector<ld>
#define vvld vector<vld>
#define I insert
#define F first
#define S second
#define pb push_back
#define all(x) x.begin(),x.end()
#define endl "\n"
#define siz(a)	((int)(a).size())

const int mod=1e9+7;
inline int add(int a,int b){a+=b;if(a>=mod)a-=mod;return a;}
inline int sub(int a,int b){a-=b;if(a<0)a+=mod;return a;}
inline int mul(int a,int b){return (a*1ll*b)%mod;}
inline int power(int a,int b){int rt=1;while(b>0){if(b&1)rt=mul(rt,a);a=mul(a,a);b>>=1;}return rt;}
inline int inv(int a){return power(a,mod-2);}

const int N=1e5+5;
int main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout<<setprecision(25);
	ll n;int m;cin>>n>>m;
	vi dp(m+1,1);dp[m]=2;
	vvi mat(m,vi(m));
	mat[0][0]=1;mat[m-1][0]=1;
	for(int i=1;i<m;i++) mat[i-1][i]=1;
	vvi res=mat;for(int i=0;i<m;i++)for(int j=0;j<m;j++)res[i][j]=(i==j);
	vvi id(m,vi(m));
	ll rpow=n-m;
	if(rpow<=0){cout<<dp[rpow]<<endl;return 0;}
	while(rpow>0){
		if(rpow&1){
			//res=res*mat
			vvi res1=id;
			for(int i=0;i<m;i++)
				for(int j=0;j<m;j++)
					for(int k=0;k<m;k++)
						res1[i][k]=add(res1[i][k],mul(res[i][j],mat[k][j]));
			res=res1;
		}
		//mat=mat*mat
		vvi res1=id;
		for(int i=0;i<m;i++)
			for(int j=0;j<m;j++)
				for(int k=0;k<m;k++)
					res1[i][k]=add(res1[i][k],mul(mat[i][j],mat[k][j]));
		mat=res1;
		rpow>>=1;
	}
	int ans=0;
	for(int i=0;i<m;i++)
		ans=add(ans,mul(dp[m-i],res[i][0]));
	cout<<ans<<endl;
}

#pragma GCC optimize("Ofast")
#include<stdio.h>
using namespace std;
long long mod=1000000007,n,m;
struct Mat{
    long long num[105][105];
    Mat(){
        long long i,j;
        for(i=0;i<105;i++)
            for(j=0;j<105;j++)
                num[i][j]=0;
    }
}ans,source,org;
Mat mul(Mat a,Mat b){
    long long i,j,k;
    Mat temp;
    for(i=1;i<=m;i++)
        for(j=1;j<=m;j++)
            for(k=1;k<=m;k++){
                temp.num[i][j]+=a.num[i][k]*b.num[k][j];
                temp.num[i][j]%=mod;
            }
    return temp;
}
Mat power(Mat a,long long val){
    if(!val)
        return org;
    //printf("%lld\n",val);
    Mat temp=power(a,val/2);
    if(val&1)
        return mul(a,mul(temp,temp));
    return mul(temp,temp);
}
int main(){
    long long i,j;
    scanf("%lld%lld",&n,&m);
    if(n<m){
        puts("1");
        return 0;
    }
    for(i=0;i<105;i++)
        org.num[i][i]=1;
    source.num[1][1]=source.num[1][m]=1;
    for(i=2;i<=m;i++)
        source.num[i][i-1]=1;
    ans=power(source,n-m);
    //puts("**");
    printf("%lld\n",(ans.num[1][1]+ans.num[1][m])%mod);
}

// warm heart, wagging tail,and a smile just for you!
//                                                                     ███████████
//                                                                   ███╬╬╬╬╬╬╬╬╬╬███
//                                                                ███╬╬╬╬╬████╬╬╬╬╬╬███
//                                            ███████████       ██╬╬╬╬╬████╬╬████╬╬╬╬╬██
//                                      █████████╬╬╬╬╬████████████╬╬╬╬╬██╬╬╬╬╬╬███╬╬╬╬╬██
//                               ████████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬██╬╬╬╬╬╬╬██
//                             ████╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬╬╬╬╬╬██
//                           ███╬╬╬█╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬███╬╬╬╬╬╬╬█████
//                         ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬████████╬╬╬╬╬██
//                       ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬╬╬╬╬███
//                     ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬██
//                 ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬████
//     █████████████╬╬╬╬╬╬╬╬██╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬██████
//   ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬██████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████╬╬╬╬╬╬╬███████████╬╬╬╬╬╬╬╬██╬╬╬██╬╬╬██
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬█╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬██
// ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬▓▓▓▓▓▓╬╬╬████╬╬████╬╬╬╬╬╬╬▓▓▓▓▓▓▓▓██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬███
// ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████▓▓▓▓▓▓▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓▓▓▓▓▓▓██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬█████
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████████
//   ███╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██
//       ██████████████  ████╬╬╬╬╬╬███████████████████████████╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████
//                         ███████                           █████  ███████████████████
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define INF (1LL<<60)
#define fs first
#define sc second
#define pb push_back
#define int long long
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i = (b-1);i>=a;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " <<
typedef pair<int,int> P;
typedef vector<vector<P> > Graph;
typedef vector<int> vec;
typedef vector<vec> mat;

void add(int &a, int b){
  a = ((a+b) % MOD + MOD) % MOD;
}

inline int mul(int a, int b) {
    #if !defined(_WIN32) || defined(_WIN64)
      return (int) ((long long) a * b % MOD);
    #endif
      unsigned long long x = (long long) a * b;
      unsigned xh = (unsigned) (x >> 32), xl = (unsigned) x, d, m;
      asm(
        "divl %4; \n\t"
        : "=a" (d), "=d" (m)
        : "d" (xh), "a" (xl), "r" (MOD)
      );
      return m;
}

inline int modpow(int a, long long b) {
  int res = 1;
  while (b > 0) {
    if (b & 1) {
      res = mul(res, a);
      }
      a = mul(a, a);
      b >>= 1;
  }
  return res;
}

inline int inv(int a) {
    a %= MOD;
    if (a < 0) a += MOD;
    int b = MOD, u = 0, v = 1;
    while (a) {
      int t = b / a;
      b -= t * a; swap(a, b);
      u -= t * v; swap(u, v);
    }
    assert(b == 1);
    if (u < 0) u += MOD;
    return u;
}

int n,m;
void matmul(mat &a, mat b){
  mat res(m,vec(m,0));
  REP(i,m) REP(j,m) REP(k,m) add(res[i][j],mul(a[i][k],b[k][j]));
  REP(i,m) REP(j,m) a[i][j] = res[i][j];
}

signed main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  //問題文を読む時間をケチらない！！
  //未定義動作に気を付ける！！
  //DPや二分探索の範囲に気をつける！！

  cin >> n >> m;

  mat a(m,vec(m,0)),x(m,vec(m,0));
  REP(i,m-1) a[i][i+1] = 1;
  a[m-1][0] = a[m-1][m-1] = 1;
  REP(i,m) x[i][i] = 1;

  while(n){
    if(n % 2) matmul(x,a);
    n /= 2;
    matmul(a,a);
  }

  REP(i,m){
    REP(j,m) cout << x[i][j] << " ";
    cout << endl;
  }

  int ans = 0;
  REP(i,m) add(ans,x[0][i]);

  cout << ans << endl;

  return 0;
}

//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")

//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
#include <bits/stdc++.h>
#include <map>
#include <vector>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <list>
#include <string>
#include <iostream>
#include <cmath>
#include <sstream>
#include <cstdlib>
#include <cctype>
#include <fstream>
#include <numeric>
#include <iterator>
#include <cstdio>
#include <cstring>

using namespace std;
//using namespace __gnu_pbds;

#define ll long long
#define ull unsigned long long
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define fread(p) freopen(p,"r",stdin);
#define fwrite(p) freopen(p,"w",stdout);
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define F first
#define S second
#define nl "\n"
#define mem(s,k) memset(s, k, sizeof(s))
#define sf scanf
#define pf printf
#define PI 2*acos(0.0)
#define ALL(p) (p.begin(),p.end())
#define mod(a,b) ((((a)%(b))+(b))%(b))
#define time_start clock_t start = clock();
#define time_end clock_t finish = clock(); cout << (double)(finish-start)/CLOCKS_PER_SEC << endl;
const double EPS = 1e-9;

////--- Graph Moves---////
//const ll xx[] = {0,0,1,-1};
//const ll yy[] = {1,-1,0,0};
//const ll xx_king[] = {0,0,1,-1,1,1,-1,-1};
//const ll yy_king[] = {1,-1,0,0,1,-1,1,-1};
//const ll xx_knight[]= {-2,-1,1,2,2,1,-1,-2};
//const ll yy_knight[]= {1,2,2,1,-1,-2,-2,-1};
////------------------////

ll POW(ll b,ll p) {ll Ans=1; while(p){if(p&1)Ans=(Ans*b);b=(b*b);p>>=1;}return Ans;}
ll BigMod(ll b,ll p,ll Mod) {ll Ans=1; while(p){if(p&1)Ans=(Ans*b)%Mod;b=(b*b)%Mod;p>>=1;}return Ans%Mod;}
ll ModInverse(ll b,ll Mod) {return BigMod(b,Mod-2,Mod);}

string tostr(int n) {stringstream rr;rr<<n;return rr.str();}
//template<typename T> using orderedSet = tree< T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

////----------- Bit Manipulation -----------------//
//int bitOn(int N,int pos){return N=N OR (1<<pos);}
//int bitOff(int N,int pos){return N= N &~(1<<pos);}
//bool bitCheck(int N,int pos){return (bool)(N & (1<<pos));}
////---------------------------------------------//

////------------ Debugging -----------------------//
#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); deb(_it, args); }
void deb(istream_iterator<string> it) {cout<<endl;}
template<typename T, typename... Args>
void deb(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << ",   ";
    deb(++it, args...);
}

#define ekhane(k) cerr << "Ekhane asche-" << k << "\n";
#define printa(a,L,R) for(int i=L;i<R;i++) cout<<a[i]<<(i==R-1?'\n':' ')
#define printv(a) printa(a,0,a.size())
#define print2d(a,r,c) for(int i=0;i<r;i++) for(int j=0;j<c;j++) cout<<a[i][j]<<(j==c-1?'\n':' ')
////-----------------------------------------------//

ll MOD = 1e9+7;
ll DIM = 0;
struct matrix{
    ll a[101][101];

    matrix(){
        mem(a,0);
    }
    void init(ll m){
        a[0][0] = 1, a[0][m-1] = 1;
        for(ll i=1; i<m; i++)
            a[i][i-1] = 1;
    }
    void print(){
        print2d(a,DIM,DIM);
    }
    matrix multiply (matrix &B){
        matrix C;
        for(ll r = 0; r < DIM; r++)
            for(ll c = 0; c < DIM; c++){
                C.a[r][c] = 0;
                for(ll k = 0 ; k < DIM; k++)
                    C.a[r][c] = (C.a[r][c] + a[r][k]*B.a[k][c])%MOD;
            }
        return C;
    }
    matrix power(ll n){
        matrix P;
        if(n == 1)
            return(*this);
        P = power(n/2);
        P = P.multiply(P);
        if(n & 1) P = multiply(P);
        return P;
    }
};

int main()
{
    ll n;
    ll m;
    cin >> n >> m;
    DIM = m;
    if(n <= m)
        return cout << "1\n", 0;
    matrix mat;
    mat.init(m);
    mat = mat.power(n-m+1);
    ll ans = 0;
    for(int i=0; i<m; i++)
        ans = (ans + mat.a[0][i])%MOD;
    cout << ans << nl;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int,int>;
#define ff first
#define ss second
#define pb push_back
#define ins insert
#define eb emplace_back
using vi = vector<int>;
const ll N = 5301;

int n;
int arr[N][N];
char c;

int solve(){
	vi dv;
	for(int i=n;i>=2;i--)if(n%i==0)dv.pb(i);
	bool val=0;
	int ans = 1;
	for(auto px: dv){
	val=0;
	for(int i=px-1;i<n;i+=px){
		for(int j=px-1;j<n;j+=px){
			int no=arr[i][j];
			if(i>px)no-=arr[i-px][j];
			if(j>px)no-=arr[i][j-px];
			if(i>px&&j>px)no+=arr[i-px][j-px];
			if(!(no==px*px||no==0))val=1;
		}
	}
	if(!val){ans = px;break;}
	}
	return ans;
}

void preproc(){
	int av=0;
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			arr[i][j]+=(j>0?arr[i][j-1]:0);
			arr[i][j]+=(i>0?arr[i-1][j]:0);
			arr[i][j]-=((j>0 and i>0)?arr[i-1][j-1]:0);
		}
	}
}

int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		for(int j=0;j<n/4;j++){
		scanf(" %c",&c);
		int v;
		if(c>='0' and c<='9')v=c-'0';
		else v=10+c-'A';
		for(int k=0;k<4;k++){
			arr[i][j*4+3-k]=v%2,v/=2;
		}}
	}
	preproc();
	printf("%d\n",solve());
	return 0;
}

//Bhargey Mehta (Sophomore)
//DA-IICT, Gandhinagar
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define ss second
#define ff first

ll n, m;
ll mod = 1e9 + 7;

void matMul(vector<vector<ll> >& x, vector<vector<ll> >& y, vector<vector<ll> >& ans)
{
    ll s;
    for(ll i=0; i<x.size(); i++)
    {
        for(ll j=0; j<y[i].size(); j++)
        {
            s = 0;
            for(ll k=0; k<x[0].size(); k++)
            {
                s = (s + x[i][k]*y[k][j]) %  mod;
            }
            ans[i][j] = s;
        }
    }
}

void matPrint(vector<vector<ll> >& x)
{
    for(ll i=0; i<x.size(); i++)
    {
        for(ll j=0; j<x[i].size(); j++)
            cout<<x[i][j]<<" ";
        cout<<endl;
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);

    cin>>n>>m;
    if(m > n)
    {
        cout<<1<<endl;
        return 0;
    }
    vector<vector<ll> > a, t, res, x(m);
    for(ll i=0; i<m; i++)
    {
        a.pb({});
        t.pb({});
        res.pb({});
        for(ll j=0; j<m; j++)
        {
            a[i].pb(0);
            t[i].pb(0);
            res[i].pb(0);
        }
    }
    a[0][0] = 1;
    a[0][m-1] = 1;
    for(ll i=1; i<m; i++) a[i][i-1] = 1;
    for(ll i=0; i<m; i++)
    {
        x.pb({});
        x[i].pb(1);
    }
    x[0][0] = 2;
    n -= 2;
    while(n-m+1)
    {
        if(n & 1)
        {
            matMul(a, t, res);
        }
        n = n >> 1;
        matMul(a, a, t);
        for(ll i=0; i<m; i++)
            for(ll j=0; j<m; j++)
                a[i][j] = t[i][j];
        for(ll i=0; i<m; i++)
            for(ll j=0; j<m; j++)
                t[i][j] = res[i][j];
    }

    matMul(a, x, t);
    cout<<t[0][0]<<endl;
    return 0;
}

#include<iostream>
#include<cstring>
using namespace std;
const int mod=(int)1e9+7;
typedef long long LL;
struct matrix
{
	int wide,leng;
	LL mat[105][105];
	matrix(int x=100,int y=1){
		wide=x;
		leng=y;
		memset(mat,0,sizeof(mat));
	}
	matrix operator *(matrix a)
	{
		matrix ret(wide,a.leng);
		LL ans;
		for(int i=0;i<wide;i++)
		for(int j=0;j<a.leng;j++){
			ans=0;
			for(int k=0;k<leng;k++)ans=(ans+mat[i][k]*a.mat[k][j])%mod;
			ret.mat[i][j]=ans;
		}
		return ret;
	}
	void operator = (matrix a){
		leng=a.leng;
		wide=a.wide;
		for(int i=0;i<wide;i++)
		for(int j=0;j<wide;j++)mat[i][j]=a.mat[i][j];
	}
};
LL n,m;
void solve()
{
	matrix a(m,1),b(m,m),c(m,m);
	for(int i=0;i<m;i++){
		a.mat[i][0]=1;
		c.mat[i][i]=1;
	}a.mat[0][0]=2;
	for(int i=0;i<m-1;i++){
		b.mat[0][i]=1;
		b.mat[i+1][i]=1;
	}
	b.mat[0][m-1]=1;
	//finish
	if(n>m){
		n=n-m;
		while(n>0){
			if(n&1)c=c*b;
			b=b*b;
			n>>=1;
		}
		a=c*a;
		cout<<a.mat[0][0]<<endl;
	}
	else {
		if(n==m)cout<<2;
		else cout<<1;
	}
}
int main()
{
	// freopen("ini","r",stdin);
	while(cin>>n>>m){
		solve();
		cout<<endl;
	}
}

#include<bits/stdc++.h>
typedef  long long int ll;
typedef  long double ld;
#define sync ios_base::sync_with_stdio(false); cin.tie(NULL)
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#define mod 1000000007
#define F first
#define S second
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
//recursions\
#pragma comment(linker, "/stack:200000000")
//loops\
#pragma GCC optimize("unroll-loops")
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,greater_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_order(ind)
using namespace std;
ll M[100][100];
void multiply(ll a[100][100],ll b[100][100],ll m)
{
	ll c[100][100];
	for(ll i=0;i<m;i++)
	{
		for(ll j=0;j<m;j++)
		{
			c[i][j]=0;
			for(ll k=0;k<m;k++)
			c[i][j]=(c[i][j]+a[i][k]*b[k][j])%mod;
		}
	}

	for(ll i=0;i<m;i++)
		for(ll j=0;j<m;j++)
			a[i][j]=c[i][j];
}
ll matpow(ll A[100][100],ll n,ll m)
{
	ll F[100][100];
	for(ll i=0;i<m;i++)
		for(ll j=0;j<m;j++)
			F[i][j]=A[i][j];

	if(n>1)
	{
		matpow(A,n/2,m);
		multiply(A,A,m);

		if(n&1)
		multiply(A,F,m);
	}
	return (2*A[0][0]+A[0][m-1])%mod;
}
int main()
{
	//migi, handle the defence...
	sync;
	ll n,m;
	cin>>n>>m;

	if(n<m)
	return cout<<1,0;

	if(n==m)
	return cout<<2,0;

	M[0][0]=M[0][m-1]=1;
	for(ll i=0;i<m-1;i++)
	M[i+1][i]=1;

	cout<<matpow(M,n-m,m);
}

#include <bits/stdc++.h>

using namespace std;
long long cmmdc (long long a, long long b)
{
    long long r;
    while(b)
    {r=a%b;a=b;b=r;}
    return a;
}
const long long mod=1000000007;
long long d[205];
long long cur[105][105],put[105][105],rez[105][105];
int main()
{
    long long i,j=0,n,pz=-1,s=0,x,y,z,a,b,c,m,pr,cnt=0,mx=0,mxx=0,x1,y1,x2,y2,cx=0,cy=0;
    cin>>n>>m;
    d[0]=1;
    if(n<=1000000)
    {
        for(i=1;i<=n;++i)
        {
            if(i>=m)
                d[i]=d[i-1]+d[i-m];
            else
                d[i]=d[i-1];
            d[i]%=mod;
        }
        cout<<d[n];
        return 0;
    }
    --n;
    n-=m;
    for(i=1;i<m;++i)
        put[i][i+1]=rez[i][i+1]=1;
    put[m][1]=rez[m][1]=1;
    put[m][m]=rez[m][m]=1;
    while(n>0)
    {
        if(n&1LL)
        {
            for(i=1;i<=m;++i)
            {
                for(j=1;j<=m;++j)
                {
                    long long sc=0;
                    for(int ii=1;ii<=m;++ii)
                        sc=(sc+rez[i][ii]*1LL*put[ii][j])%mod;
                    cur[i][j]=sc;
                }
            }
            for(i=1;i<=m;++i)
                for(j=1;j<=m;++j)
                    rez[i][j]=cur[i][j];
            --n;
        }
        else
        {
            for(i=1;i<=m;++i)
            {
                for(j=1;j<=m;++j)
                {
                    long long sc=0;
                    for(int ii=1;ii<=m;++ii)
                        sc=(sc+put[i][ii]*1LL*put[ii][j])%mod;
                    cur[i][j]=sc;
                }
            }
            for(i=1;i<=m;++i)
                for(j=1;j<=m;++j)
                    put[i][j]=cur[i][j];
            n>>=1LL;
        }
    }
    long long sc=0;
    for(i=1;i<=m;++i)
    {
        sc=sc+rez[i][m];
        sc%=mod;
    }
    cout<<sc;
}

#define NDEBUG
NDEBUG

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cstring>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <memory>
#include <queue>
#include <random>

#define FOR(i, n) for (int i = 0; i < (n); ++i)

using namespace std;

// TC_REMOVE_BEGIN
/// caide keep
bool __hack = std::ios::sync_with_stdio(false);
/// caide keep
auto __hack1 = cin.tie(nullptr);
// TC_REMOVE_END

// Section with adoption of array and vector algorithms.

//#include "collections/multivector.h"
//
//template <class T, template <class, size_t> class B1, template <class, size_t> class B2>
//vec<T, 2> operator*(multivec_impl::vec_mixin<B1, T, 2>& a, multivec_impl::vec_mixin<B2, T, 2>& b) {
//    size_t n = a.template dim<0>();
//    size_t n1 = a.template dim<1>();
//    size_t m = b.template dim<0>();
//    size_t m1 = b.template dim<1>();
//    assert(n1 == m);
//    auto ret = make_vec<T>(n, m1);
//    forn (size_t, i, n) {
//        forn (size_t, j, m1) {
//            T sum = {};
//            forn (size_t, k, n1) {
//                sum += a(i, k) * b(k, j);
//            }
//            ret(i, j) = sum;
//        }
//    }
//    return ret;
//};
//
//template <class T, template <class, size_t> class B2>
//vec<T, 2>& operator*=(vec<T, 2>& a, multivec_impl::vec_mixin<B2, T, 2>& b) {
//    return a = a * b;
//};
//
//template <class T, template <class, size_t> class B1, template <class, size_t> class B2>
//vec<T, 2> operator+(multivec_impl::vec_mixin<B1, T, 2>& a, multivec_impl::vec_mixin<B2, T, 2>& b) {
//    size_t n = a.template dim<0>();
//    size_t n1 = a.template dim<1>();
//    size_t m = b.template dim<0>();
//    size_t m1 = b.template dim<1>();
//    assert(n == m && n1 == m1);
//    auto ret = make_vec<T>(n, n1);
//    forn (size_t, i, n) {
//        forn (size_t, j, n1) {
//            ret(i, j) = a(i, j) + b(i, j);
//        }
//    }
//    return ret;
//};
//
//template <class T, template <class, size_t> class B2>
//vec<T, 2>& operator+=(vec<T, 2>& a, multivec_impl::vec_mixin<B2, T, 2>& b) {
//    size_t n = a.template dim<0>();
//    size_t n1 = a.template dim<1>();
//    size_t m = b.template dim<0>();
//    size_t m1 = b.template dim<1>();
//    assert(n == m && n1 == m1);
//    forn (size_t, i, n) {
//        forn (size_t, j, n1) {
//            a(i, j) += b(i, j);
//        }
//    }
//    return a;
//};
//
//template <class T, template <class, size_t> class B1, template <class, size_t> class B2>
//vec<T, 2> operator-(multivec_impl::vec_mixin<B1, T, 2>& a, multivec_impl::vec_mixin<B2, T, 2>& b) {
//    size_t n = a.template dim<0>();
//    size_t n1 = a.template dim<1>();
//    size_t m = b.template dim<0>();
//    size_t m1 = b.template dim<1>();
//    assert(n == m && n1 == m1);
//    auto ret = make_vec<T>(n, n1);
//    forn (size_t, i, n) {
//        forn (size_t, j, n1) {
//            ret(i, j) = a(i, j) - b(i, j);
//        }
//    }
//    return ret;
//};
//
//template <class T, template <class, size_t> class B2>
//vec<T, 2>& operator-=(vec<T, 2>& a, multivec_impl::vec_mixin<B2, T, 2>& b) {
//    size_t n = a.template dim<0>();
//    size_t n1 = a.template dim<1>();
//    size_t m = b.template dim<0>();
//    size_t m1 = b.template dim<1>();
//    assert(n == m && n1 == m1);
//    forn (size_t, i, n) {
//        forn (size_t, j, n1) {
//            a(i, j) -= b(i, j);
//        }
//    }
//    return a;
//};
//
//template <class T, template <class, size_t> class B1>
//vec<T, 2> operator-(multivec_impl::vec_mixin<B1, T, 2>& a) {
//    size_t n = a.template dim<0>();
//    size_t n1 = a.template dim<1>();
//    auto ret = make_vec<T>(n, n1);
//    forn (size_t, i, n) {
//        forn (size_t, j, n1) {
//            ret(i, j) = -a(i, j);
//        }
//    }
//    return ret;
//};

namespace matrix_utils {

typedef vector<vector<int64_t>> Matrix;
typedef vector<int64_t> Vector;

template<class T>
vector<vector<T>> Mul(const vector<vector<T>>& a, const vector<vector<T>>& b, const T MOD) {
    vector<vector<T>> res(a.size(), vector<T>(b[0].size(), 0));
    FOR(i, a.size()) {
        FOR(j, b[0].size()) {
            FOR(k, a[0].size()) {
                res[i][j] += (a[i][k] * b[k][j]) % MOD;
                if (res[i][j] >= MOD) {
                    res[i][j] -= MOD;
                }
            }
        }
    }
    return res;
}

template<class T>
vector<T> MulVec(const vector<T>& v, const vector<vector<T> >& a, const T MOD) {
    vector<T> res(v.size(), 0);
    FOR(i, v.size()) {
        FOR(j, a[0].size()) {
            res[i] += (a[i][j] * v[i]) % MOD;
            if (res[i] >= MOD) {
                res[i] -= MOD;
            }
        }
    }
    return res;
}

template<class T>
vector<vector<T>> Pow(vector<vector<T>> a, int64_t p, const T MOD) {
    const int n = (int)a.size();
    vector<vector<T>> res(n, vector<T>(n, 0));
    for (int i = 0; i < n; ++i) res[i][i] = 1;
    for (; p; p /= 2) {
        if (p & 1) res = Mul<T>(res, a, MOD);
        a = Mul<T>(a, a, MOD);
    }
    return res;
}

}

namespace template_util {

    constexpr int bytecount(uint64_t x) {
        return x ? 1 + bytecount(x >> 8) : 0;
    }

    template<int N>
    struct bytetype {

    };

    /// caide keep
    template<uint64_t N>
    struct minimal_uint : bytetype<bytecount(N)> {
    };
}

template<class T>
T next(istream& in) {
    T ret;
    in >> ret;
    return ret;
}

using namespace matrix_utils;

const int64_t MOD = (int64_t) 1e9 + 7;

void solve(istream& in, ostream& out) {
    auto n = next<int64_t>(in);
    auto m = next<int>(in);
    if (n < m) {
        out << 1 << "\n";
        return;
    }
    Vector v(m, 0);
    v[0] = 1;

    Matrix a = vector<vector<int64_t>>(m, vector<int64_t>(m));
    FOR(c, m-1) {
        a[c + 1][c] = 1;
    }
    FOR(c, m) {
        a[c][m-1] = 1;
    }
//    a[0][m-1] = 1;
//    a[1][m-1] = 1;
    a = Pow(a, n, MOD);
    v = MulVec(v, a, MOD);
    out << v[0] << "\n";
}

int main() {
    solve(cin, cout);
    return 0;
}

/*alurquiza*/
//1117D
#include <bits/stdc++.h>

using namespace std;

const int TAM = 100,MOD = 1e9 + 7;

struct matrix{
    int N,M;
    long long mat[TAM][TAM];

    matrix(int _N = TAM,int _M = TAM){
        N = _N; M = _M;

        for(int i = 0;i < N;i++)
            for(int j = 0;j < M;j++)
                mat[i][j] = 0;
    }

    matrix Iden(int _N = TAM){
        matrix ret(_N,_N);

        for(int i = 0;i < _N;i++)
            ret.mat[i][i] = 1;

        return ret;
    }

    friend matrix operator *(const matrix &a,const matrix &b){
        matrix c(a.N,b.M);

        for(int i = 0;i < a.N;i++)
            for(int j = 0;j < b.M;j++)
                for(int k = 0;k < a.M;k++)
                    c.mat[i][j] = (c.mat[i][j] + a.mat[i][k] * b.mat[k][j]) % MOD;

        return c;
    }

};

matrix pot(matrix base,long long exp){
    matrix ret = ret.Iden(base.N);

    while(exp){
        if(exp & 1)
            ret = ret * base;
        exp /= 2;
        base = base * base;
    }

    return ret;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

//    freopen(".in","r",stdin);

    long long N;int M;
    cin >> N >> M;

    if(M > N){
        cout << "1\n";
        return 0;
    }

    matrix b(M,M);

    b.mat[0][0] = b.mat[0][M - 1] = 1;
    for(int i = 1;i < M;i++)
        b.mat[i][M - (i + 1)] = 1;
//        b.mat[i][i - 1] = 1;

    matrix vc(M,1);
    for(int i = 0;i < M;i++)
        vc.mat[i][0] = 1;

    matrix sol = pot(b,N - M + 1) * vc;

//    cerr << sol.mat[0][0] << '\n';
//    sol = sol * vc;

    cout << sol.mat[0][0] << '\n';

    return 0;
}
/*
//1117E
#include <bits/stdc++.h>

using namespace std;

map<vector<char>,int> ID;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

//    freopen(".in","r",stdin);

    string S;
    cin >> S;

    int N = S.size();

    vector<char> T[N];
    for(int i = 0;i < S.size();i++){

        vector<int> B26(3);
        int copia = i,cont = 0;
        while(copia){
            B26[cont++] = copia % 26;
            copia /= 26;
        }

        for(int j = 0;j < 3;j++)
            T[i].push_back(B26[j] + 'a');

        ID[T[i]] = i;
    }

    vector<char> R[N];
    for(int q = 0;q < 3;q++){
        string p = "";
        for(int i = 0;i < N;i++)
            p += T[i][q];

        cout << "? " << p << endl;

        string resp;
        cin >> resp;

        for(int i = 0;i < N;i++){
            R[i].push_back(resp[i]);
        }
    }

    string sol(N,'0');
    for(int i = 0;i < N;i++){
        int pos = ID[R[i]];
        sol[pos] = S[i];
    }

    cout << "! " << sol << endl;

    return 0;
}
*/

#include<bits/stdc++.h>
using namespace std;
#define ll unsigned long long
ll arr[102][102],md=1000000007,brr[102][102];
void multiply(ll a[102][102], ll b[102][102])
{
    // Creating an auxiliary matrix to store elements
    // of the multiplication matrix
    ll mul[102][102];
    for (int i = 0; i < 3; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            mul[i][j] = 0;
            for (int k = 0; k < 3; k++)
                mul[i][j] =(mul[i][j]+ ( a[i][k]*b[k][j] )%md)%md;
        }
    }

    // storing the muliplication resul in a[][]
    for (int i=0; i<3; i++)
        for (int j=0; j<3; j++)
            a[i][j] = mul[i][j];  // Updating our matrix
}
void power(ll F[102][102], ll n)
{

    // Multiply it with initial values i.e with
    // F(0) = 0, F(1) = 1, F(2) = 1
    while(n)
    {
        if(n&1)
        {
            multiply(F,arr);
        }
        multiply(arr,arr);
        n/=2;
    }

}
int main()
{
    ios::sync_with_stdio(0);
    //   freopen("input.txt","r",stdin);
    ll n,m;
    cin>>n>>m;
    arr[0][0]=1;
    arr[0][m-1]=1;
    for(int i=1;i<m;i++)
    {
        arr[i][i-1]=1;
    }
    for(int i=0;i<m;i++)
    {
        for(int j=0;j<m;j++)
        {
            brr[i][j]=arr[i][j];
        }
    }
    power(brr,n-m);
    cout<<(brr[0][0]+brr[0][m-1])%md;
}

#include <bits/stdc++.h>
#define lli long long int

using namespace std;

vector<vector<lli> > matmul(vector<vector<lli>> a, vector<vector<lli>> b, lli M){
	vector<vector<lli> > c;
	c.resize(M);
	for (lli i = 0; i < M; ++i) c[i].resize(M);

	for (lli i = 0; i < M; ++i)
	{
		for (lli j = 0; j < M; ++j)
		{
			for (lli k = 0; k < M; ++k)
			{
				c[i][j] += (a[i][k] * b[k][j]) % (1000000000 + 7);
			}
		}
	}

	return c;
}

int main(){
	ios_base::sync_with_stdio(false);
	#ifndef ONLINE_JUDGE
		freopen("in.txt","r",stdin);
	#endif

	lli N, M; cin >> N >> M;

	vector<vector<lli> > a;
	a.resize(M);
	for (lli i = 0; i < M; ++i) a[i].resize(M);
	a[0][0] = 1; a[M-1][0] = 1;
	for (lli i = 0; i < M-1; ++i)
	{
		a[i][i+1] = 1;
	}

	// cout << a[0][0] << " " << a[0][1] << endl;
	// cout << a[1][0] << " " << a[1][1] << endl;

	vector<vector<lli> > result;
	result.resize(M);
	for (lli i = 0; i < M; ++i) result[i].resize(M);
	for (lli i = 0; i < M; i++) result[i][i] = 1;

	N = N - M + 1;

	while(N > 0){
		if(N % 2 == 1){
			result = matmul(result, a, M);
		}
		a = matmul(a, a, M);
		// cout << a[0][0] << " " << a[0][1] << endl;
		// cout << a[1][0] << " " << a[1][1] << endl;
		N /= 2;
	}

	cout << result[0][0] + result[M-1][0] << endl;

	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define maxn 105
#define int long long
#define eps 1e-4
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#pragma GCC optimize(2)
#define lowbit(x) ((x)&-(x))
#define ull unsigned long long
#define db double
#define ld long double
#define mod 1000000007
struct matrix{
    ll m[maxn][maxn];
};
matrix matrix_mul(matrix a,matrix b,ll n){
    matrix c{};
    for (ll i = 0; i <n ; ++i) {
        for (ll j = 0; j <n ; ++j) {
            c.m[i][j]=0;
        }
    }
    for (ll i = 0; i <n ; ++i) {
        for (ll j = 0; j <n ; ++j) {
            for (ll k = 0; k <n ; ++k) {
                c.m[i][j]+=a.m[i][k]*b.m[k][j]%mod;
            }
            c.m[i][j]%=mod;
        }
    }
    return c;
}
matrix slow_pow(ll n,matrix a,ll pow){
    matrix b{};
    for (ll i = 0; i <n ; ++i) {
        for (ll j = 0; j <n ; ++j) {
            if(i==j)b.m[i][j]=1;
            else b.m[i][j]=0;
        }
    }
    while(pow){
        if(pow&1)b=matrix_mul(b,a,n);
        a=matrix_mul(a,a,n);
        pow>>=1;
    }
    return b;
}
signed main(){
    IOS
    int n,m;
    cin>>n>>m;
    if(n<m)cout<<1;
    else{
        matrix a{};
        for (int i = 1; i <m ; ++i) {
            for (int j = 0; j <m ; ++j) {
                if(j==i-1){
                    a.m[i][j]=1;
                }else{
                    a.m[i][j]=0;
                }
            }
        }
        a.m[0][0]=1;
        a.m[0][m-1]=1;
        int tmp=n-m+1;
        a=slow_pow(m,a,tmp);
        int ans=0;
        for (int k = 0; k <m ; ++k) {
            ans+=a.m[0][k];
        }
        cout<<ans;
    }

    return 0;
}

/*
.....   .   .   .   .
  .    . .   . .   . .
  .   .....   .   .....
  .  .     .  .  .     .
*/
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stdio.h>
#include <cstdio>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <random>
#include <iomanip>
#include <bitset>

using namespace std;

template<typename T> void uin(T &a, T b) {
    if (b < a) {
        a = b;
    }
}

template<typename T> void uax(T &a, T b) {
    if (b > a) {
        a = b;
    }
}

#define int unsigned long long
#define left left228
#define right right228

const int MOD = 1e9 + 7;

vector< vector<int> > mult(vector< vector<int> > a, vector< vector<int> > b) {
    int n = (int)a.size() - 1;
    int m = (int)b[1].size() - 1;
    vector< vector<int> > c(n + 1, vector<int> (m + 1, 0));
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            for (int k = 1; k < (int)a[1].size(); ++k) {
                c[i][j] += a[i][k] * b[k][j];
                if (((k >> 4) << 4) == k) {
                    c[i][j] %= MOD;
                }
            }
            c[i][j] %= MOD;
        }
    }
    return c;
}

int A[111][111], B[111][111], C[111][111];

vector< vector<int> > power(vector< vector<int> > a, int b) {
    vector< vector<int> > res = a;
    --b;
    while (b) {
        if (b & 1) {
            res = mult(res, a);
        }
        a = mult(a, a);
        b >>= 1LL;
    }
    return res;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector< vector<int> > dp(2, vector<int> (m + 1, 0));
    for (int i = 1; i <= m; ++i) {
        dp[1][i] = 1;
        if (i == m) dp[1][i] = 2;
    }
    if (n == m) {
        cout << 2 << endl;
        return 0;
    }
    vector< vector<int> > p(m + 1, vector<int> (m + 1, 0));
    p[1][m] = 1;
    p[m][m] = 1;
    for (int i = m - 1; i > 0; --i) {
        p[i + 1][i] = 1;
    }
    p = power(p, n - m);
    vector< vector<int> > ans = mult(dp, p);
    cout << ans[1][m] << endl;
    return 0;
}

/*
2 0 3

3 1 2
1 2

*/

#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll n;
int m;
long long temp[110][110],ans[110][110],b[110][110],a[110][110];
const int mod = 1e9+7;
void output(long long a[][110],int n,int m){
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++)
			printf("%lld ",a[i][j]);
		cout<<endl;
	}
}
long long f_mul(long long a,long long b,int r){
	ll res = 0;
	while(b){
		if(b&1) res=(res+a)%r;
		a=a%r+a%r;
		b>>=1;
	}
	return res;
}
void matri_mul(long long a[][110],long long b[][110],int n,int m,int t){
	//memset(temp,0,sizeof(temp));
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
			long long x = 0;
			for(int k = 1; k <= t; k++)
				//x=(x+f_mul(a[i][k],b[k][j],mod))%mod;
				x=(x+a[i][k]*b[k][j])%mod;
			temp[i][j]=x;
		}
	}
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= m; j++)
			a[i][j]=temp[i][j];
}
void matri_pow(long long a[][110],long long t,int n){
	memset(ans,0,sizeof(ans));
	for(int i = 1; i <= n; i++) ans[i][i]=1;
	while(t){
		if(t&1) matri_mul(ans,a,n,n,n);
		matri_mul(a,a,n,n,n);
		t>>=1;
	}
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= n; j++)
			a[i][j]=ans[i][j];
}
int main(){
	scanf("%lld%d",&n,&m);
	if(n<=m){
		printf("%d\n",1);
		return 0;
	}
	a[1][1]=a[1][m]=1;
	for(int i = 2; i <= m; i++)
		a[i][i-1] = 1;
	for(int i = 1; i <= m; i++)
		b[i][i]=1;
	matri_pow(a,n-m+1,m);
	for(int i = 1; i <= m; i++)
		b[i][1]=1;
	matri_mul(a,b,m,1,m);
	printf("%lld\n",a[1][1]);
}

#include <bits/stdc++.h>

using namespace std;

typedef long long int lli;

#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define MOD (lli)1000000007

int m;

lli** mult(lli** A, lli** B)
{
    lli** C = (lli**)malloc(m * sizeof(lli*));
    for (int i = 0; i < m; i++)
        C[i] = (lli*)malloc(m * sizeof(lli));

    for (int i = 0; i < m; i++) {
        for (int j = 0; j < m; j++) {
            for (int k = 0; k < m; k++) {
                C[i][j] += ((A[i][k] % MOD) * (B[k][j] % MOD)) % MOD;
                if(C[i][j] > MOD) C[i][j] -= MOD;
            }
        }
    }

    return C;
}

lli** expM(lli** A, lli n)
{
    if (n == 1)
        return A;
    else if ((n % 2) == 1)
        return mult(A, expM(A, n - 1));
    else
        return mult(expM(A, n / 2), expM(A, n / 2));
}

int main()
{
    lli n;
    cin >> n >> m;

    lli** T = (lli**)malloc(m * sizeof(lli*));
    for (int i = 0; i < m; i++)
        T[i] = (lli*)malloc(m * sizeof(lli));
    for (int i = 0; i < m; i++) {
        for (int j = 0; j < m; j++)
            T[i][j] = 0;
    }
    for (int i = 0; i < m - 1; i++)
        T[i][i + 1] = 1;
    T[m - 1][0] = 1;
    T[m - 1][m - 1] = 1;

    lli** expT = expM(T, n - 1);

    lli ans = 0;

    for (int j = 0; j < m - 1; j++) {
        ans += expT[0][j];
        if(ans > MOD) ans -= MOD;
    }
    ans += (expT[0][m-1]%MOD + expT[0][m-1]%MOD)%MOD;
    if(ans > MOD) ans -= MOD;

    printf("%lld\n", ans);
    return 0;
}

#include<bits/stdc++.h>
#define MOD 1000000007
#define lli long long int
using namespace std;

lli f[103][103];
void multiply(int m, lli a[][100], lli b[][100]){
    lli ans[m][m];
    for(int i=0;i<m;i++){
        for(int j=0;j<m;j++){
            ans[i][j] = 0;
            for(int k=0;k<m;k++){
                ans[i][j] = (ans[i][j] + (a[i][k]%MOD)*(b[k][j]%MOD)%MOD)%MOD;

            }
        }
    }
    for(int i=0;i<m;i++)
        for(int j=0;j<m;j++)
            a[i][j] = ans[i][j];
}
void print(lli a[][103], int m){

    for(int i=0;i<m;i++) {
        for(int j=0;j<m;j++) {
            cout<<a[i][j]<<" ";
        }
        cout<<endl;
    }
}
void power(lli n, lli ans[][100],  int m){
    lli b[m][100];
    for(int i=0;i<m;i++) {
        for(int j=0;j<m;j++) {
            b[i][j] = f[i][j];
            ans[i][j] = f[i][j];
            }
    }
        n--;
    while(n){
        if(n%2)
            multiply(m, ans, b);
        else
            multiply(m, b, b);
        n/=2;
    }
}

int main(){
    lli n;
    int m;
    cin>>n>>m;
    for(int i=0;i<m;i++){
        for(int j=0;j<m;j++){
            f[i][j]=0;
            if(i==j+1) f[i][j]+=1;
        }
    }
    if(m>n){
        return 1;
    }
    f[0][0] = 1;
    f[0][m-1] = 1;
    lli ans[m][100];
    //cout<<n-m+1<<endl;
    power(n-m+1, ans, m);
    lli fin=0;
    for(int i=0;i<m;i++){
        fin = (fin + ans[0][i])%MOD;

    }
    cout<<fin<<endl;
}

#include<bits/stdc++.h>
using namespace std;
using vvi = vector<vector<long long>>;
const int MOD = (long long )1e9+7;
vvi pro(vvi m1,vvi m2){
    int n = m1.size();
    int m = m1[0].size();
    int o = m2[0].size();
    vvi v(n,vector<long long>(o,0));
    for(int i=0;i<n;i++){
        for(int j = 0;j<o;j++){
            for(int k = 0;k<m;k++){
                v[i][j]= (v[i][j]%MOD + ((m1[i][k]%MOD)*(m2[k][j]%MOD))%MOD)%MOD;
            }
        }
    }
    return v;
}

vvi im(long long n){
    vvi ar(n,vector<long long>(n,0));
    for(int i=0;i<n;i++){
        ar[i][i] = 1;
    }
    return ar;
}

vvi pow(vvi a,long n){
    if(n==0) return im(a.size());
    vvi l = pow(a,n/2);
    if(n%2==0)
        return pro(l,l);
    else
        return pro(a,pro(l,l));
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    long long n;int m;
    cin >> n >> m;
    vvi z(m,vector<long long>(m,0));
    z[0][0] = 1;
    z[0][m-1] = 1;
    z[m-1][m-2] = 1;
    vvi fm(m,vector<long long>(1,0));
    for(int i=m;i>=1;i--){
        fm[m-i][0] = i;
    }
    z = pow(z,n-m);
    // for(int i=0;i<m;i++) {for(int j =0;j<m;j++) cout << z[i][j] << " "; cout << "\n"; }
    // for(int i=0;i<m;i++){
    //     cout << fm[i][0] <<  "\n";
    // }
    vvi vz(1,vector<long long>(z[0]));
    vvi ans = pro(vz,fm);
    cout << ans[0][0];
    return 0;
}

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ll long long int
#define F first
#define S second
#define pb push_back

using namespace std;
using namespace __gnu_pbds;

typedef tree<ll, null_type, less<ll>, rb_tree_tag,
tree_order_statistics_node_update>
new_data_set;

const ll N=100005;

const ll mod = 1000000007;
ll fact[N], invfact[N];
inline ll add(ll x, ll y){ x += y; if(x >= mod) x -= mod; return x;}
inline ll sub(ll x, ll y){ x -= y; if(x < 0) x += mod; return x;}
inline ll mul(ll x, ll y){ return (((ll) x) * y) % mod;}
inline ll powr(ll a, ll b){
    ll x = 1 % mod;
    while(b){
        if(b & 1) x = mul(x, a);
        a = mul(a, a);
        b >>= 1;
    }
    return x;
}
inline ll inv(ll a){ return powr(a, mod - 2);}
void pre(){
    fact[0] = invfact[0] = 1;
    for(ll i = 1;i < N; i++) fact[i] = mul(i, fact[i - 1]);
    invfact[N - 1] = inv(fact[N - 1]);
    for(ll i = N - 2; i >= 1; i--) invfact[i] = mul(invfact[i + 1], i + 1);
    assert(invfact[1] == 1);
}

inline ll C(ll n, ll k){
    if(n < k || k < 0) return 0;
    return mul(fact[n], mul(invfact[k], invfact[n - k]));
}

int main()
{
    pre();
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    // ll t;
    // cin>>t;
    // while(t--)
    {
        ll i,j,k,n,m,ans=0,cnt=0,sum=0;
        ll x,y,x1,y1;
        cin>>x>>y>>x1>>y1;
        cin>>n;
        string s;
        cin>>s;
        ll up=0,dn=0,rt=0,lf=0;
        for(i=0;i<n;i++){
            if(s[i]=='U'){
                up++;
            }
            else if(s[i]=='D'){
                dn++;
            }
            else if(s[i]=='L'){
                lf++;
            }
            else if(s[i]=='R'){
                rt++;
            }
        }

    }
}

#include <cstdio>
#define p 1000000007
#define llg long long
using namespace std;

int n;
struct DT {
	llg a[109][109];
	void clear(int ln, int lm)
		{for (int i = 0; i <= ln; ++i) for (int j = 0; j <= lm; ++j) a[i][j] = 0; }
} F, G, T, dp;
llg m;

void mult(DT &A, DT B, int ln, int lm) {
	T.clear(ln, lm);
	for (int i = 1; i <= ln; ++i) for (int j = 1; j <= lm; ++j)
		for (int k = 1; k <= ln; ++k) (T.a[i][j] += A.a[i][k] * B.a[k][j] % p) %= p;
	for (int i = 1; i <= ln; ++i) for (int j = 1; j <= lm; ++j)
		A.a[i][j] = T.a[i][j];
}
void copy(DT &A, DT B) {
	for (int i = 1; i <= n; ++i) for (int j = 1; j <= n; ++j)
		A.a[i][j] = B.a[i][j];
}
void fsq(DT &A, DT &B, llg kn) {
	int ind = false;
	while (kn) {
		if (kn & 1)
			if (ind) mult(B, A, n, n);
			else copy(B, A), ind = true;
		mult(A, A, n, n); kn >>= 1;
	}
}

int main() {
//	freopen("a.in", "r", stdin);
	scanf("%lld%d", &m, &n);
	dp.a[1][1] = dp.a[2][1] = 1;
	for (int i = 3; i <= n; ++i) dp.a[i][1] = 1;
	F.a[1][1] = 1; F.a[1][n] = 1;
	for (int i = 2; i <= n; ++i) F.a[i][i - 1] = 1;
	fsq(F, G, m - n + 1);
	mult(G, dp, n, 1);
	printf("%lld\n", G.a[1][1]);
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

long long const MOD = 1e9 + 7;

long long bin_pow(long long p)
{
    if (p < 0)
        return 1;
    if (p == 1)
        return 2;
    if (p == 0)
        return 1;
    if (p % 2 == 0)
    {
        long long r = bin_pow(p / 2);
        return (r * r) % MOD;
    }
    else
        return bin_pow(p - 1);
}

int main()
{
    long long n, m;
    cin >> n >> m;
    long long ans = bin_pow(n - m);
    cout << (ans + 1) % MOD;

    return 0;
}

#include "bits/stdc++.h"

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back
#pragma GCC optimize ("-O3")

using namespace std;

#define DEBUG_IS_VALID

#ifdef DEBUG_IS_VALID
#define DEB 1
#else
#define DEB 0
#endif
#define DUMPOUT cout
#define dump(...) if(DEB) DUMPOUT<<"  "<<#__VA_ARGS__<<" :["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl<<"    "; if(DEB) dump_func(__VA_ARGS__)
template<typename T1,typename T2>ostream& operator << (ostream& os, pair<T1,T2> p){cout << "(" << p.first << ", " << p.second << ")"; return os;}
template<typename T>ostream& operator << (ostream& os, vector<T>& vec) { os << "{"; for (int i = 0; i<vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : ", "); os << "}"; return os; }
template<typename T>ostream& operator << (ostream& os, set<T>& st){cout << "{"; for(auto itr = st.begin(); itr != st.end(); itr++) cout << *itr << (next(itr)!=st.end() ? ", " : ""); cout << "}"; return os;}
template<typename T1,typename T2>ostream& operator << (ostream& os, map<T1,T2> mp){cout << "{"; for(auto itr = mp.begin(); itr != mp.end(); itr++) cout << "(" << (itr->first) << ", " << (itr->second) << ")" << (next(itr)!=mp.end() ? "," : ""); cout << "}"; return os; }

void dump_func(){DUMPOUT << endl;}
template <class Head, class... Tail>void dump_func(Head&& head, Tail&&... tail){ DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...);}
template<class T> inline bool chmax(T& a,T const& b){if(a>=b) return false; a=b; return true;}
template<class T> inline bool chmin(T& a,T const& b){if(a<=b) return false; a=b; return true;}
void _main();
int main(){ cin.tie(0); ios::sync_with_stdio(false); _main(); return 0;}

using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

const int mod=1e9+7,INF=1<<29;
const double EPS=1e-5,PI=3.1415926535897932384626;
const ll lmod = 1e9+7,LINF=1LL<<59;

template<int MOD> struct ModInt {
    static const int Mod = MOD; unsigned x; ModInt() : x(0) { }
    ModInt(signed sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    ModInt(signed long long sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    int get() const { return (int)x; }
    ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; }
    ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }
    ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
    ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
    ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
    ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }
    ModInt inverse() const { long long a = x, b = MOD, u = 1, v = 0;
        while (b) { long long t = a / b; a -= t * b; std::swap(a, b); u -= t * v; std::swap(u, v); }
        return ModInt(u); }
    bool operator==(ModInt that) const { return x == that.x; }
    bool operator!=(ModInt that) const { return x != that.x; }
    ModInt operator-() const { ModInt t; t.x = x == 0 ? 0 : Mod - x; return t; }
};
template<int MOD> ostream& operator<<(ostream& st, const ModInt<MOD> a) { st << a.get(); return st; };
template<int MOD> ModInt<MOD> operator^(ModInt<MOD> a, unsigned long long k) {
    ModInt<MOD> r = 1; while (k) { if (k & 1) r *= a; a *= a; k >>= 1; } return r; }
template<typename T, int FAC_MAX> struct Comb { vector<T> fac, ifac;
    Comb(){fac.resize(FAC_MAX,1);ifac.resize(FAC_MAX,1); for(int i = 1; i < FAC_MAX; i++)fac[i]=fac[i-1]*i;
        ifac[FAC_MAX-1]=T(1)/fac[FAC_MAX-1];for(int i = FAC_MAX-2; i >= 1; i--)ifac[i]=ifac[i+1]*T(i+1);}
    T aPb(int a, int b) { if (b < 0 || a < b) return T(0); return fac[a] * ifac[a - b]; }
    T aCb(int a, int b) { if (b < 0 || a < b) return T(0); return fac[a] * ifac[a - b] * ifac[b]; }
    T nHk(int n, int k) { if (n == 0 && k == 0) return T(1); if (n <= 0 || k < 0) return 0;
        return aCb(n + k - 1, k); }}; // nHk = (n+k-1)Ck : n is separator

using mint =  ModInt<int(1e9+7)>;
using vm = vector<mint>;

template <class T>
struct Matrix {
  vector<vector<T>> dat;
  Matrix(signed N):dat(N,vector<T>(N)){};
  Matrix(const vector<vector<T>>& dat):dat(dat){};
};
template <class T>
Matrix<T> operator*(Matrix<T>& a,Matrix<T>& b) {
  int N = a.dat.size();
	int x,y,z; Matrix<T > res(N);
	rep(x,N) rep(z,N) rep(y,N) {
		res.dat[x][y] += a.dat[x][z] * b.dat[z][y];
	}
	return res;
}
template<class T> Matrix<T> operator^(Matrix<T> a, unsigned long long k) {
  assert(k>=0);
  int N = a.dat.size();
  Matrix<T> res(N);
  for(int i = 0; i < N; i++) res.dat[i][i] = 1;
  while (k) {
    if (k & 1) res = a * res;
    a = a * a;
    k >>= 1;
  }
  return res;
}

void _main(){
  // int N; cin >> N ;
  // int N,K; cin >> N >> K ;
  // int a,b; cin >> a >> b ;
  ll N,M; cin >> N >> M ;
	// if(N-M+1<0){
	// 	cout << "1" << endl;
	// 	return;
	// }
  Matrix<mint> A(M);
  A.dat[0][0] = 1;
  A.dat[0][M-1] = 1;
  rep(i,M-1) A.dat[i+1][i] = 1;
  auto An = A^(N-M+1);
  mint ans(0);
  rep(i,M) ans += An.dat[0][i];
  cout << ans << endl;
}

#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long
#define IO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)

#define mod 1000000007
int n,m;
int ans;

main()
{
    IO;
    cin>>n>>m;
    ans++;
    int up=n/m;
    ans+=(up%mod)*(n%mod)+up;
    ans%=mod;
    up=(1+up)*up/2;
    up=(up%mod)*m;
    up%=mod;
    ans=ans-up;
    ans%=mod;
    cout<<ans<<endl;
}

#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <cassert>
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// head

ll _,n;
namespace linear_seq
{
	const int N=10010;
	ll res[N],base[N],_c[N],_md[N];
	vector<ll> Md;
	void mul(ll *a,ll *b,int k)
	{
		rep(i,0,k+k) _c[i]=0;
		rep(i,0,k) if (a[i]) rep(j,0,k) _c[i+j]=(_c[i+j]+a[i]*b[j])%mod;
		for (int i=k+k-1; i>=k; i--) if (_c[i])
				rep(j,0,SZ(Md)) _c[i-k+Md[j]]=(_c[i-k+Md[j]]-_c[i]*_md[Md[j]])%mod;
		rep(i,0,k) a[i]=_c[i];
	}
	int solve(ll n,VI a,VI b)
	{
		ll ans=0,pnt=0;
		int k=SZ(a);
		assert(SZ(a)==SZ(b));
		rep(i,0,k) _md[k-1-i]=-a[i];
		_md[k]=1;
		Md.clear();
		rep(i,0,k) if (_md[i]!=0) Md.push_back(i);
		rep(i,0,k) res[i]=base[i]=0;
		res[0]=1;
		while ((1ll<<pnt)<=n) pnt++;
		for (int p=pnt; p>=0; p--)
		{
			mul(res,res,k);
			if ((n>>p)&1)
			{
				for (int i=k-1; i>=0; i--) res[i+1]=res[i];
				res[0]=0;
				rep(j,0,SZ(Md)) res[Md[j]]=(res[Md[j]]-res[k]*_md[Md[j]])%mod;
			}
		}
		rep(i,0,k) ans=(ans+res[i]*b[i])%mod;
		if (ans<0) ans+=mod;
		return ans;
	}
	VI BM(VI s)
	{
		VI C(1,1),B(1,1);
		int L=0,m=1,b=1;
		rep(n,0,SZ(s))
		{
			ll d=0;
			rep(i,0,L+1) d=(d+(ll)C[i]*s[n-i])%mod;
			if (d==0) ++m;
			else if (2*L<=n)
			{
				VI T=C;
				ll c=mod-d*powmod(b,mod-2)%mod;
				while (SZ(C)<SZ(B)+m) C.pb(0);
				rep(i,0,SZ(B)) C[i+m]=(C[i+m]+c*B[i])%mod;
				L=n+1-L;
				B=T;
				b=d;
				m=1;
			}
			else
			{
				ll c=mod-d*powmod(b,mod-2)%mod;
				while (SZ(C)<SZ(B)+m) C.pb(0);
				rep(i,0,SZ(B)) C[i+m]=(C[i+m]+c*B[i])%mod;
				++m;
			}
		}
		return C;
	}
	int gao(VI a,ll n)
	{
		VI c=BM(a);
		c.erase(c.begin());
		rep(i,0,SZ(c)) c[i]=(mod-c[i])%mod;
		return solve(n,c,VI(a.begin(),a.begin()+SZ(c)));
	}
};
int f[105];
int main()
{
    ll n,m;
    cin>>n>>m;
    for(int i=1;i<=m;i++) f[i]=1;
    for(int i=m;i<=100;i++)
	f[i]=(f[i-1]+f[i-m])%mod;
    vector<int> v;
    for(int i=1;i<=100;i++)
	v.push_back(f[i]);
    cout<<linear_seq::gao(v,n);
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
ll n,m;
ll kissme(ll a,ll x)
{
	ll ret=1;
	for(;x>0;x>>=1,a=a*a%mod) if(x&1) ret=ret*a%mod;
	return ret;
}
int main()
{
	scanf("%lld%lld",&n,&m);
	if(n<m) puts("1");
	else printf("%lld\n",(kissme(2,n/m)+1)%mod);
	return 0;
}

#include <bits/stdc++.h>
#define int int64_t
using namespace std;

const int MOD = 1000000007;

typedef vector<vector<int>> vvi;

vvi multiply(vvi a, vvi b){
    int n = a.size();
    int m = a[0].size();

    int p = b[0].size();
    vvi res(n, vector<int>(p));
    for(int i = 0; i < n; i++){
        for(int j = 0; j < p; j++){
            res[i][j] = 0;
            for(int k = 0; k < m; k++){
                res[i][j] += ((a[i][k] % MOD) * (b[k][j] % MOD)) % MOD;
                /*
                if(res[i][j] >= MOD){
                    res[i][j] -= MOD;
                }
                */
                res[i][j] %= MOD;
            }
        }
    }
    return res;
}

vvi binpow(vvi a, int p){
    if(p == 1){
        return a;
    }
    if(p % 2 == 0){
        vvi t = binpow(a, p / 2);
        return multiply(t, t);
    }
    vvi t = binpow(a, p - 1);
    return multiply(a, t);
}

signed main(){
    int n, m;
    cin >> n >> m;
    vector<int> a(m, 1);
    vvi matrix(m, vector<int>(m, 0));
    for(int i = 0; i < m - 1; i++){
        matrix[i][i + 1] = 1;
    }
    matrix[m - 1][m - 1] = 1;
    matrix[m - 1][0] = 1;
    matrix = binpow(matrix, n);
    int ans = 0;
    for(int i = 0; i < m; i++){
        ans += a[i] * matrix[i][0];
    }
    cout << ans;
}

#include <bits/stdc++.h>

using namespace std;

typedef long long int lli;

#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define MOD (lli)1000000007

int m;

lli** mult(lli** A, lli** B)
{
    lli** C = (lli**)malloc(m * sizeof(lli*));
    for (int i = 0; i < m; i++)
        C[i] = (lli*)malloc(m * sizeof(lli));

    for (int i = 0; i < m; i++) {
        for (int j = 0; j < m; j++) {
            for (int k = 0; k < m; k++) {
                C[i][j] += ((A[i][k] % MOD) * (B[k][j] % MOD)) % MOD;
                if(C[i][j] > MOD) C[i][j] -= MOD;
            }
        }
    }

    return C;
}

lli** expM(lli** A, lli n)
{
    if (n == 1)
        return A;
    else if ((n % 2) == 1)
        return mult(A, expM(A, n - 1));
    else{
    	lli** aux = expM(A, n / 2);
        return mult(aux, aux);
    }
}

int main()
{
    lli n;
    cin >> n >> m;

    lli** T = (lli**)malloc(m * sizeof(lli*));
    for (int i = 0; i < m; i++)
        T[i] = (lli*)malloc(m * sizeof(lli));
    for (int i = 0; i < m; i++) {
        for (int j = 0; j < m; j++)
            T[i][j] = 0;
    }
    for (int i = 0; i < m - 1; i++)
        T[i][i + 1] = 1;
    T[m - 1][0] = 1;
    T[m - 1][m - 1] = 1;

    lli** expT = expM(T, n - 1);

    lli ans = 0;

    for (int j = 0; j < m - 1; j++) {
        ans += expT[0][j];
        if(ans > MOD) ans -= MOD;
    }
    ans += (expT[0][m-1]%MOD + expT[0][m-1]%MOD)%MOD;
    if(ans > MOD) ans -= MOD;

    printf("%lld\n", ans);
    return 0;
}

#pragma comment(linker, "/STACK:33554432")
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <unordered_map>
#include <cmath>
#include <iterator>
#include <stack>
#include <unordered_set>
#include <iomanip>
#include <ctime>
#include <cstring>

using namespace std;
void dout() { cerr << endl; }

template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
	cerr << H << ' ';
	dout(T...);
}

using ll = long long;
using pii = pair<int, int>;
using ld = long double;
using pll = pair<long long, long long>;

const int MAXN = 2 * 100002;
const int MAXK = 26 * 2;
const int MOD = 1e9 + 7;
const int MOD2 = 998244353;
const ld EPS = 1e-9;
const ll INF = numeric_limits<int> ::max() / 4;
const ll MSIZE = 20;
const ld pi = acos(-1.0);
const int H = 8;

ll n, m;

ll mult_mod(ll a, ll b)
{
	return (a * b) % MOD;
}

ll add_mod(ll a, ll b)
{
	return (a + b) % MOD;
}
void precalc()
{
}

vector<vector<ll>> operator * (vector<vector<ll>> one, vector<vector<ll>> other)
{
	vector<vector<ll>> res;
	res.assign(m, vector<ll>(m));
	for (int i = 0; i < m; ++i)
	{
		for (int j = 0; j < m; ++j)
		{
			ll curr = 0;
			for (int k = 0; k < m; ++k)
			{
				curr = add_mod(curr, mult_mod(one[i][k], other[k][j]));
			}

			res[i][j] = curr;
		}
	}
	return res;
}

vector<vector<ll>> ed;

vector<vector<ll>> bin_pow(vector<vector<ll>> mat, ll power)
{
	if (power == 0)
		return ed;
	if (power % 2 == 1)
	{
		auto val = bin_pow(mat, power - 1);
		return mat * val;
	}
	auto val = bin_pow(mat, power >> 1);
	return val * val;
}

vector<vector<ll>> ma;

void solve()
{
	cin >> n >> m;
	ed.assign(m, vector<ll>(m));
	ma.assign(m, vector<ll>(m));
	for (int i = 0; i < m; ++i)
	{
		ed[i][i] = 1;
	}

	for (int i = 0; i < m; ++i)
	{
		ma[0][i] = 1;
	}
	ma[m - 1][0] = 1;

	ma = bin_pow(ma, n);

	cout << ma[0][0];

}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	cout << fixed << setprecision(20);
#ifdef LOCAL
	freopen("input.in", "r", stdin);
	freopen("output.out", "w", stdout);
#endif
	precalc();
	solve();
#ifdef LOCAL
	cout << '\n' << (double)clock() / CLOCKS_PER_SEC << '\n';
#endif
}

#include <bits/stdc++.h>
using namespace std;

/////////////////// TYPES & MACROS ///////////////////////////////
#define all(x) x.begin(), x.end()
#define vv vector
#define exist(s, e) (s.find(e) != s.end())
template <class T> constexpr inline int SZ(const T &x) { return x.size(); }
using i64 = int64_t;
using i32 = int32_t;
//#define int i64
const char el = '\n';
template <class T> constexpr inline bool rmn(T &a, T b) { return a > b ? (a = b, true) : false; }
template <class T> constexpr inline bool rmx(T &a, T b) { return a < b ? (a = b, true) : false; }
const i32 MOD = 1e9 + 7, INF = 0x3f3f3f3f;
const i64 INFLL = ((i64)INF << 32) | INF;

//////////////////// DEBUG /////////////////////////////////////////
#ifdef LOCAL
template <class... Args> void dprint(Args... args) { ((std::cerr << args << ", "), ...) << el; }
#else
template <class... Args> void dprint(Args... args) {}
#endif
template <class... Args> void print(Args... args) { (std::cout << ... << args) << el; }

/////////////////// VARIABLES & FUNCTIONS//////////////////////////
vv<vv<i32>> adj;
vv<i32> vis, color;
/*
 * Author : Jakob Kogler, Madhur Chauhan
 * Use : Modular Arithmetic
 * Time Complexity : O(1)
 * Space Complexity: O(1)
 * Usage Notes: Template argument is the modulus which is set to default: 1e9+7. A modular int can be created by:
 *                  Modular<> m=56; // creates a modular integer initialize to 56 in MOD = 1e9+7
 *                  using MInt = Modular<998244353>; // MInt can be used like regular integer
 *                  vector<MInt> dp(10, Mint(0)); // creater a vector with values initialized to 0
 *                  cout << m * 1'000'000'000'000 << endl; // will not overflow
 */

template <int MOD = 1'000'000'007>
struct modular {
	int value;

	modular(long long v = 0) {
		value = v % MOD;
		if (value < 0) value += MOD;
	}
	modular(long long a, long long b) : value(0) {
		*this += a;
		*this /= b;
	}
	modular &operator+=(modular const &b) {
		value += b.value;
		if (value >= MOD) value -= MOD;
		return *this;
	}
	modular &operator-=(modular const &b) {
		value -= b.value;
		if (value < 0) value += MOD;
		return *this;
	}
	modular &operator*=(modular const &b) {
		value = (long long)value * b.value % MOD;
		return *this;
	}

	friend modular mexp(modular a, long long e) {
		modular res = 1;
		while (e) {
			if (e & 1) res *= a;
			a *= a, e >>= 1;
		}
		return res;
	}
	friend modular inverse(modular a) {
		int phi = MOD - 1; // change this for general MOD where a^phi = 1 (mod MOD)
		return mexp(a, phi - 1);
	}

	modular &operator/=(modular const &b) { return *this *= inverse(b); }
	friend modular operator+(modular a, const modular b) { return a += b; }
	friend modular operator-(modular a, const modular b) { return a -= b; }
	friend modular operator-(const modular a) { return 0 - a; }
	friend modular operator*(modular a, const modular b) { return a *= b; }
	friend modular operator/(modular a, const modular b) { return a /= b; }
	friend std::ostream &operator<<(std::ostream &os, const modular &a) { return os << a.value; }
	friend std::istream &operator>>(std::istream &is, modular &a) {
		long long temp;
		is >> temp;
		a = modular(temp);
		return is;
	}
	friend bool operator==(modular const &a, modular const &b) { return a.value == b.value; }
	friend bool operator!=(modular const &a, modular const &b) { return a.value != b.value; }
};

/*
 * Author: Madhur Chauhan, Ankur Dua
 * Use: Easy and expressive matrix operations
 * Features: Highly optimized for modular arithmetic and matrix multiplication, matrix exponentiation
 * Time Complexity: O(N^3) cache-efficient matrix multiplication
 * Notes: 1. Use Modular class from modular.h to take advantage of optimized modular arithmetic
 *        2. There are helper member functions like transpose, mexp (modular exponentiation)
 * Status: Tested: Modular exponentiation, Rest of the operations are pending
 */
template <typename T>
struct matrix_base {
	matrix_base(int r, int c, T init = 0) : _mat(r, vector<T>(c, init)) {}

	constexpr matrix_base operator+(const matrix_base &o) const {
		matrix_base ret(row(), col());
		scan(ret, _mat, o, std::plus<T>());
		return ret;
	}
	constexpr matrix_base operator-(const matrix_base &o) const {
		matrix_base ret(row(), col());
		scan(ret, _mat, o, std::minus<T>());
		return ret;
	}
	constexpr matrix_base &operator+=(const matrix_base &o) {
		scan(_mat, _mat, o, std::plus<T>());
		return _mat;
	}
	constexpr matrix_base &operator-=(const matrix_base &o) {
		scan(_mat, _mat, o, std::minus<T>());
		return _mat;
	}
	matrix_base transpose() const {
		const int BLOCKSIZE = 32, rows = row(), columns = col();
		matrix_base ret(columns, rows);
		for (int i = 0; i < rows; i += BLOCKSIZE)
			for (int j = 0; j < columns; j += BLOCKSIZE)
				for (int k = i, lim_k = min(rows, i + BLOCKSIZE); k < lim_k; ++k)
					for (int l = j, lim_l = min(columns, j + BLOCKSIZE); l < lim_l; ++l)
						ret[l][k] = _mat[k][l];
		return ret;
	}

	vector<T> &operator[](const size_t idx) { return _mat[idx]; }

	vector<vector<T>> _mat;
	constexpr int row() const { return _mat.size(); }
	constexpr int col() const { return _mat[0].size(); }

	// this function is called by op: +,-,+=,-=
	template <typename F>
	constexpr void transform(matrix_base &rhs, const matrix_base &op1, const matrix_base &op2, const F &&op) {
		for (size_t i = 0; i < rhs.size(); ++i)
			std::transform(begin(op1[i]), end(op1[i]), begin(op2[i]), begin(rhs[i]), op);
	}
};

template <typename T>
struct matrix : public matrix_base<T> {
	using base_type = matrix_base<T>;

	constexpr matrix(int r, int c, T init = 0) : base_type(r, c, init) {}

	constexpr matrix operator*(const matrix &o) const {
		base_type tp = o.transpose();
		const int x = base_type::row(), y = base_type::col(), z = o.row();
		matrix ret(x, z);
		for (int i = 0; i < x; ++i)
			for (int j = 0; j < z; ++j)
				for (int k = 0; k < y; ++k)
					ret[i][j] += base_type::_mat[i][k] * tp[j][k];

		return ret;
	}

	matrix &operator*=(const matrix &o) {
		(*this) = (*this) * o;
		return *this;
	}
};

template <int MOD>
struct matrix<modular<MOD>> : public matrix_base<modular<MOD>> {
	using base_type = matrix_base<modular<MOD>>;

	matrix(int r, int c, modular<MOD> init = 0) : base_type(r, c, init) {}

	matrix operator*(const matrix &o) const {
		base_type tp = o.transpose();
		const int x = base_type::row(), y = base_type::col(), z = o.row();
		matrix ret(x, z);
		const int64_t base = mexp(modular<MOD>(2), 64).value;
		for (int i = 0; i < x; ++i) {
			for (int j = 0; j < z; ++j) {
				uint64_t s = 0;
				uint32_t carry = 0;
				for (int k = 0; k < y; ++k) {
					auto cur = s;
					s += static_cast<uint64_t>(base_type::_mat[i][k].value) * static_cast<uint64_t>(tp[j][k].value);
					carry += s < cur;
				}
				ret[i][j] = ((s % MOD) + base * carry) % MOD;
			}
		}
		return ret;
	}

	matrix &operator*=(const matrix &o) {
		(*this) = (*this) * o;
		return *this;
	}
};

template <typename T>
matrix<T> mexp(matrix<T> a, long long e) {
	int n = a.row();
	matrix<T> ret(n, n, 0);
	for (int i = 0; i < n; ++i)
		ret[i][i] = 1;
	while (e) {
		if (e & 1) ret *= a;
		a *= a, e >>= 1;
	}
	return ret;
}

///////////////////// MAIN STARTS //////////////////////////////////
int32_t main() {
	ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
	cout << fixed << setprecision(13), cerr << fixed << setprecision(3);

	i64 n;
	i32 m;
	cin >> n >> m;
	if (n < m) {
		cout << 1 << el;
		return 0;
	}
	matrix<modular<>> mat(m, m, 0);
	mat[0][0] = mat[0][m - 1] = 1;
	for (int i = 1; i < m; ++i)
		mat[i][i - 1] = 1;
	mat = mexp(mat, n - m + 1);
	cout << mat[0][0] + mat[0][m - 1] << el;

	return 0;
}

#include <stdio.h>
#define MOD 1000000007

int matrix[66][100][100];
int src[100][100];
int dest[100][100];

inline int add(int a, int b, int m = MOD)
{
	return (a + b) % m;
}

inline int sub(int a, int b)
{
	return (MOD + a - b) % MOD;
}

inline int prod(int a, int b, int m = MOD)
{
	return (long long)a * b % m;
}

int power(int a, int n, int m = MOD)
{
	if (!n) return 1;
	int mid = power(a, n / 2, m);
	mid = prod(mid, mid, m);
	if (n % 2) mid = prod(mid, a, m);
	return mid;
}

int inverse(int a)
{
	return power(a, MOD - 2);
}

void matmul(int a[100][100], int b[100][100], int c[100][100], int n)
{
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
		{
			int sum = 0;
			for (int k = 0; k < n; k++) sum = add(sum, prod(b[i][k], c[k][j]));
			a[i][j] = sum;
		}
	}
}

void matcpy(int a[100][100], int b[100][100], int n)
{
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++) a[i][j] = b[i][j];
	}
}

void matprint(int a[100][100], int n)
{
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++) printf("%d ", a[i][j]);
		printf("\n");
	}
}

void matpower(long long k, int n)
{
	matcpy(matrix[0], src, n);
	for (int i = 0; i < n; i++) matrix[65][i][i] = 1;
	for (int i = 0; i < 63; i++)
	{
		matmul(matrix[i + 1], matrix[i], matrix[i], n);
		if ((k >> i) & 1)
		{
			matmul(matrix[64], matrix[65], matrix[i], n);
			matcpy(matrix[65], matrix[64], n);
		}
	}
	matcpy(dest, matrix[65], n);
}

int main()
{
	long long N;
	int M;
	scanf("%I64d %d", &N, &M);
	for (int i = 1; i < M; i++) src[i - 1][i] = 1;
	src[M - 1][0] = 1;
	src[M - 1][M - 1] = 1;
	matpower(N - M + 1, M);
	printf("%d\n", dest[M - 1][0] + dest[M - 1][M - 1]);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define de(x) cout<<#x<<"="<<x<<","
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define dee(x) cout<<#x<<"="<<x<<"\n"
#define mes(p) memset(p,0,sizeof(p))
#define fi first
#define se second
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define sz(x) (int)x.size()
#define pb push_back
//#define ls (rt<<1)
//#define rs (ls|1)
#define all(x) x.begin(),x.end()
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
//#include <ext/pb_ds/priority_queue.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> os;
//typedef priority_queue <pair<int, int>, greater<pair<int, int> >, pairing_heap_tag> heap;
const int maxn=100005;

typedef long long ll;
typedef vector <int > vi;
const ll mod=1000000007;
ll n;
ll m;
ll dp[105];
struct node{
	ll a[105][105];
}a,s;
ll add(ll x,ll y){
	x+=y;
	if(x>=mod) x-=mod;
	return x;
}
node mul(const node &a,const node &b){
	node c;
	rep(i,0,m)
	rep(j,0,m)c.a[i][j]=0;
//	rep(i,0,m)c.a[i][i]=1;
	rep(i,0,m)
	rep(j,0,m)
	rep(k,0,m)c.a[i][j]=add(c.a[i][j],1ll*a.a[i][k]*b.a[k][j]%mod);
	return c;
}
int main(){
	ios_base::sync_with_stdio(0);
    cin.tie(0);
	cin>>n>>m;
	if(n<m){
		cout << 1;
		return 0;
	}
	n--;
	rep(i,0,m)
	rep(j,0,m)a.a[i][j]= s.a[i][j]=0;

	a.a[0][0]=1, a.a[0][m-1]=1;
	rep(i,1,m) a.a[i][i-1]=1;
	rep(i,0,m) s.a[i][i]=1;
	while(n){
		if(n&1) s=mul(s,a);
		a=mul(a,a);
		n>>=1;
	}
	ll ans = add(1ll*s.a[0][0]%mod,s.a[0][m-1]);
	cout << ans;
	return 0;
}

#include<bits/stdc++.h>
#define In_the_name_of_allah_the_merciful ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define Alhamdulillah return 0;
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ins insert
#define fi first
#define se second
#define pi pair<int,int>
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define sz(v) ((ll)((v).size()))
#define reset(v,val) memset(v,val,sizeof(v));
#define rep(i, x, n) for ( i = x; i<=(ll)(n); i++)
#define irep(i, x, n) for( i = x; i<(ll)(n); i++)
#define _rep(i, x, n) for ( i =x; i>=(ll)(n); i--)
#define _irep(i, x, n) for( i =x; i>(ll)(n); i--)
using namespace std;
typedef   long long     ll;
const long long  mod=1e9+7;
const ll MOD = 1e9 + 7;
ll res=0,ans=0,sm=0,dp[500005]={0},vis[500005],edge=-1;
ll timer=0,low[500005],tin[500005];
set<ll>st,st1,st2;
string s,s1,s2;
vector<ll>v,vnode,vans,v1,v3;
vector< pi >vv,adj[500005];
vector< pair< ll,pi> > vvv;
priority_queue <ll> q;
map<ll,ll>cost;
map<pi,ll> red;
map< pair<pi,ll>,ll >able,edge_pos;
ll xa,xb,xc,ya,yb,yc,start,fin,x1,y1;
set<ll> ::iterator it,it1,it2;
int voyel(char c){
	if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u'||c=='y')return 1;
	return 0;
}
ll DIM=101;
struct matrix{

  vector< vector<int> > a;
	void unit_matrix(ll x) {
		DIM=x;
		a.resize(DIM);
		for(int i=0;i<DIM;i++)a[i].resize(DIM,0);
	for(int i=0;i<DIM;i++)
	  for(int j=0;j<DIM;j++)a[i][j]=0;
		a[0][0] = 1; a[0][DIM-1] = 1;
		for(int i=1;i<DIM;i++){
			a[i][i-1]=1;
		}
	}

	matrix operator* (const matrix b) {
		matrix c;
		DIM=b.a[0].size();
		c.unit_matrix(DIM);
		for (int k = 0; k < DIM; ++ k) {
			for (int i = 0; i < DIM; ++i) {
				for (int j = 0; j < DIM; ++j) {
					c.a[i][j] = (c.a[i][j]%mod + (a[i][k]%mod * b.a[k][j]%mod)%mod) % MOD;
				}
			}
		}
		return c;
	}
};
matrix pow_matrix(matrix a, ll n) {
	if (n == 1) return a;
	matrix b ;
	b.unit_matrix(a.a[0].size());
	b= pow_matrix(a, n / 2);
	b = b * b;
	if (n & 1) b = b * a;
	return b;
}

int main(){
In_the_name_of_allah_the_merciful
    ll m,k,n;
	ll i=0,j=0,z=0,mx=0,nb0=0,nb=0,nbmax=0,nbinf=0,nb2=0,mm=5e9,idx=0,ok=0,l,r,negatif=0,positif=0,q,w,d,b;
	char c;
  // freopen("a.txt","r",stdin);
    cin>>n>>m;
   	matrix A,B;
	A.unit_matrix(m);
	B.unit_matrix(m);
	B=pow_matrix(A,n-m+1);
	res=(B.a[0][0]+B.a[0][1])%MOD;
	cout<<res;
Alhamdulillah
 }

#include <iostream>

using namespace std;

int Mod = 1000000007;

struct Matrix {
    long long v[100][100];
    int row, col;

    Matrix(int row, int col) {
        this->row = row;
        this->col = col;
        memset(v, 0, sizeof(v));
    }

    Matrix operator *(const Matrix &t) {
        Matrix tmp = Matrix(this->row, t.col);
        for (int i = 0; i < this->row; i++) {
            for (int j = 0; j < t.col; j++) {
                for (int k = 0; k < this->col; k++) {
                    tmp.v[i][j] += (v[i][k] % Mod * (t.v[k][j] % Mod));
                }
            }
        }
        return tmp;
    }
} ;

long long N;
int M;
Matrix quickPow(Matrix m, long long n) {
    Matrix tmp = Matrix(M, M);
    for (int i = 0; i < M; i++) {
        tmp.v[i][i] = 1;
    }
    while (n) {
        if (n & 1) {
            tmp = tmp * m;
        }
        m = m * m;
        n >>= 1;
    }
    return tmp;
}

int main() {
    cin >> N >> M;
    Matrix m0 = Matrix(M, M);
    m0.v[0][M - 1] = m0.v[0][0] = 1;
    for (int i = 1; i < M; i++) {
        m0.v[i][i - 1] = 1;
    }
    Matrix m1 = Matrix(M, 1);
    for (int i = 0; i < M; i++) {
        m1.v[i][0] = 1;
    }
    cout << (quickPow(m0, N - M + 1) * m1).v[0][0] % Mod;
    return 0;
}

#include <bits/stdc++.h>
#define lli long long int
#define mod (1000000000 + 7)

using namespace std;

vector<vector<lli> > matmul(vector<vector<lli> > a, vector<vector<lli> > b, lli M){
    vector<vector<lli> > c;
    c.resize(M);
    for (lli i = 0; i < M; ++i) c[i].resize(M);

    for (lli i = 0; i < M; ++i)
    {
        for (lli j = 0; j < M; ++j)
        {
            for (lli k = 0; k < M; ++k)
            {
                c[i][j] = ((c[i][j] % mod) + (a[i][k] % mod) * (b[k][j] % mod)) % mod;
            }
        }
    }

    return c;
}

int main(){
    ios_base::sync_with_stdio(false);
    #ifndef ONLINE_JUDGE
        freopen("in.txt","r",stdin);
    #endif

    lli N, M; cin >> N >> M;

    vector<vector<lli> > a;
    a.resize(M);
    for (lli i = 0; i < M; ++i) a[i].resize(M);
    a[0][0] = 1; a[M-1][0] = 1;
    for (lli i = 0; i < M-1; ++i)
    {
        a[i][i+1] = 1;
    }

    // cout << a[0][0] << " " << a[0][1] << endl;
    // cout << a[1][0] << " " << a[1][1] << endl;

    vector<vector<lli> > result;
    result.resize(M);
    for (lli i = 0; i < M; ++i) result[i].resize(M);
    for (lli i = 0; i < M; i++) result[i][i] = 1;

    N = N - M + 1;

    while(N > 0){
        if(N % 2 == 1){
            result = matmul(result, a, M);
        }
        a = matmul(a, a, M);
        // cout << a[0][0] << " " << a[0][1] << endl;
        // cout << a[1][0] << " " << a[1][1] << endl;
        N /= 2;
    }

    cout << ((result[0][0] % mod) + (result[M-1][0] % mod)) % mod << endl;

    return 0;
}

#include<bits/stdc++.h>
#define mod 1000000007
#define max 105
//#define max1 60000000
#define inf INT_MAX
using namespace std;
typedef  long long int ll;
template<typename T> inline T maxi(T a,T b){return a>b?a:b;}
template<typename T> inline T mini(T a,T b){return a<b?a:b;}
template<typename T> inline T absl(T a){return a>0?a:-a;}
template<typename T> inline T gcd(T a,T b){T t;if(a<b){while(a){t=a;a=b%a;b=t;}return b;}else{while(b){t=b;b=a%b;a=t;}return a;}}
#define mp(a,b) make_pair(a,b)
//###################################################------------------------------------------------------#######################################

ll a[max];
ll matrix[max][max];
ll resmatrix[max][max];
ll m;
void multiply(ll a[max][max],ll b[max][max]){
    ll mul[max][max];
    for (ll i = 0; i < m; i++)
    {
        for (ll j = 0; j < m; j++)
        {
            mul[i][j] = 0;
            for (ll k = 0; k < m; k++)
                mul[i][j] += (a[i][k]*b[k][j])%mod;
                mul[i][j]%=mod;
        }
    }
     for (ll i=0; i<m; i++)
        for (ll j=0; j<m; j++)
            a[i][j] = mul[i][j];
}
ll solve1(ll y){
    while(y>0){
        if(y&1){
            multiply(resmatrix,matrix);
        }
        y=y/2;
        multiply(matrix,matrix);
    }
    return (2*resmatrix[0][0]+a[2*m-1]*resmatrix[0][m-1])%mod;
}
ll solve(ll n, ll m){
    memset(matrix, 0, sizeof(matrix));
    matrix[0][0] = 1;
    matrix[0][m-1] =1;
    for(ll i =1;i<m;++i){
        matrix[i][i-1] =1;
    }
    for(ll i =0;i<m;++i){
        for(ll j =0;j<m;++j){
            resmatrix[i][j] = matrix[i][j];
        }
    }
    if(n<m)return 1;
    if(n==m)return 2;
    return solve1(n-1-m-1);

}
void input(){
  ll n;
  cin>>n>>m;
  for(int i =0;i<m;++i)a[i]=1;
  for(int i =m;i<=m+m+1;++i)a[i]=a[i-1]+a[i-m];
 // cout<<a[n]<<endl;
  cout<<solve(n,m)<<endl;

}
int main(){
    input();
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#ifdef ONLINE_JUDGE
    #define cerr if(false)cerr
#else
    #define cerr if(true)cerr
#endif
#define inputarr(a,n) for(ll i=0;i<n;i++) cin>>a[i];
#define prllarr(a,n) for(ll i=0;i<n;i++) cerr<<a[i]<<" "; cerr<<endl;
#define pb push_back
#define ll long long
#define mod 1000000007
#define foi ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
#define in(n) scanf("%lld",&n);
#define in2(x,y) scanf("%lld %lld",&(x),&(y));
#define in3(x,y,z) scanf("%lld %lld %lld",&(x),&(y),&(z));
#define in4(x,y,z,m) scanf("%lld %lld %lld %lld",&(x),&(y),&(z),&(m));
#define out(n) printf("%lld\n",n);
#define out2(x,y) printf("%lld %lld\n",x,y);
#define test(t)  ll t; in(t);while(t--)
#define set(arr,n,s) for(ll i=0;i<n;i++){arr[i]=s;}
#define fr(i,s,e) for(ll i=s;i<e;i++)
#define frr(i,s,e) for(ll i=e-1;i>=s;i--)
#define vi vector<ll>
#define see2(x,y) cerr<<x<<" "<<y<<endl;
#define see(x) cerr<<x<<endl;
#define see3(x,y,z) cerr<<x<<" "<<y<<" "<<z<<endl;
#define see4(x,y,z,m) cout<<x<<" "<<y<<" "<<z<<" "<<m<<endl;
#define invec(a,n) fr(i,0,n){ll x;in(x) a.pb(x);}
#define vii vector<pair<ll,ll> >
#define pii pair<ll,ll>
#define all(a) a.begin(),a.end()
const ll d4i[4]={-1, 0, 1, 0}, d4j[4]={0, 1, 0, -1};
const ll d8i[8]={-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8]={0, 1, 1, 1, 0, -1, -1, -1};
ll power(ll x,ll y,ll p){ll res=1;x=x%p;while(y>0){if(y&1){res=(res*x)%p;} y=y>>1;x=(x*x)%p;}return res;}
ll modInverse(ll a,ll p){return power(a,p-2,p);}//used with feemat little//only for prime
void gcd(ll a, ll b, ll& d, ll& u, ll& v) {
    if (b == 0) {
        d = a;
        u = 1;
        v = 0;
    } else {
        gcd(b, a % b, d, v, u);
        // a u + b v = b u' + (a - (a/b) * b) v'
        // = a v' + b (u' - (a/b) v').
        v -= a / b * u;
    }
}
ll Inverse(ll a, ll m) {
    a %= m;
    if (a < 0) a += m;
    ll d, u, v;
    gcd(a, m, d, u, v);
    assert(d == 1);
    u %= m;
    if (u < 0) u += m;
    return u;
}

ll gcd(ll x,ll y){if(x==0 || y==0){return max(y,x);}return gcd(y%x,x);}
ll gcdExtended(ll a,ll b,ll &x,ll &y){if(a==0){x=0;y=1;return b;}ll x1,y1;ll gcd = gcdExtended(b%a,a,x1,y1);x=y1-(b/a)*x1;y=x1;return gcd;}//o(log(b))
;

const ll siz=100;
ll m;
struct mat{
    ll a[siz][siz]={0};
    mat(ll id=1){
        memset(a, 0, sizeof(a));
        fr(i,0,siz)a[i][i]=id;
    }
    mat operator*(const mat &o) const
    {
        ll n=m;
        mat res(0);

        fr (i, 0, n)
            fr (j, 0, n)
                fr (k, 0, n)
                    res.a[i][j] = (res.a[i][j] + a[i][k]*o.a[k][j]) % mod;

        return res;
    }

};

mat binpow(mat a, ll n)
{
    mat ans(1);

    while (n)
    {
        if (n & 1)
            ans = ans * a;
        a = a * a;
        n >>= 1;
    }

    return ans;
}
void print(mat &a){
     for (ll i=0;i<m;i++)
        {
            for(ll j=0;j<m;j++)
                cout << a.a[i][j] << " ";
            cout << '\n';
        }

}

int main(){

    ll n;
    in2(n,m)
    if(n<m){
        cout<<1<<endl;
        return 0;

    }
    mat a(0);
    a.a[0][0]=1;
    a.a[0][m-1]=1;
    for(ll i=1;i<m;i++){
        a.a[i][i-1]=1;
    }
    print(a);
    auto ans=binpow(a,n-m+1);
    ll ret=0;
    for(ll i=0;i<m;i++){
        ret+=ans.a[0][i];
        ret%=mod;
    }
    cout<<ret<<endl;

}
/*error-----
convert every int to long long eg-1LL
create array with proper analysis of problem constrain
check mod also
*/

#include<bits/stdc++.h>
#define int long long
using namespace std;
#define For(i,a,b) for ( int i=(a);i<=(b);i++ )
#define Dow(i,a,b) for ( int i=(a);i>=(b);i-- )
const int N=105,Mo=1e9+7;
inline int read()
{
	int x=0,f=0; char ch=getchar();
	while(!isdigit(ch)) f|=(ch=='-')?1:0,ch=getchar();
	while(isdigit(ch)) x=x*10ll+(ch^48),ch=getchar();
	return (f)?-1ll*x:x;
}
int n,m;
struct Node
{
	int a[N][N];
	Node(){memset(a,0,sizeof(a));}
	inline Node friend operator * (const Node &s,const Node &t)
	{
		Node ans;
		For(i,0,m-1) For(j,0,m-1) For(k,0,m-1)
		ans.a[i][j]=(ans.a[i][j]+s.a[i][k]*t.a[k][j]%Mo+Mo)%Mo;
		return ans;
	}
};
Node pre,extend;
inline Node ksm(Node x,int y)
{
	Node ans;
	For(i,0,m-1) For(j,0,m-1) ans.a[i][j]=(i==j);
	while(y)
	{
		if(y&1ll) ans=ans*x;
		x=x*x;
		y>>=1ll;
	}
	return ans;
}
signed main()
{
	n=read(),m=read();
	if(n<m) return printf("0\n"),0;
	For(i,0,m-1) pre.a[0][i]=1;
	extend.a[0][0]=1;
	For(i,0,m-1) if(i>=1) extend.a[i-1][i]=1;
	extend.a[m-1][0]=1;
	extend=ksm(extend,n-m+1);
	pre=pre*extend;
	printf("%lld\n",pre.a[0][0]);
	return 0;
}

#include <bits/stdc++.h>
#define lli long long int
#define mod (1000000000 + 7)

using namespace std;

vector<vector<lli> > matmul(vector<vector<lli>> a, vector<vector<lli>> b, lli M){
	vector<vector<lli> > c;
	c.resize(M);
	for (lli i = 0; i < M; ++i) c[i].resize(M);

	for (lli i = 0; i < M; ++i)
	{
		for (lli j = 0; j < M; ++j)
		{
			for (lli k = 0; k < M; ++k)
			{
				c[i][j] += ((a[i][k] % mod) * (b[k][j] % mod)) % mod;
			}
		}
	}

	return c;
}

int main(){
	ios_base::sync_with_stdio(false);
	#ifndef ONLINE_JUDGE
		freopen("in.txt","r",stdin);
	#endif

	lli N, M; cin >> N >> M;

	vector<vector<lli> > a;
	a.resize(M);
	for (lli i = 0; i < M; ++i) a[i].resize(M);
	a[0][0] = 1; a[M-1][0] = 1;
	for (lli i = 0; i < M-1; ++i)
	{
		a[i][i+1] = 1;
	}

	// cout << a[0][0] << " " << a[0][1] << endl;
	// cout << a[1][0] << " " << a[1][1] << endl;

	vector<vector<lli> > result;
	result.resize(M);
	for (lli i = 0; i < M; ++i) result[i].resize(M);
	for (lli i = 0; i < M; i++) result[i][i] = 1;

	N = N - M + 1;

	while(N > 0){
		if(N % 2 == 1){
			result = matmul(result, a, M);
		}
		a = matmul(a, a, M);
		// cout << a[0][0] << " " << a[0][1] << endl;
		// cout << a[1][0] << " " << a[1][1] << endl;
		N /= 2;
	}

	cout << (result[0][0] + result[M-1][0]) % mod << endl;

	return 0;
}

#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <iomanip>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>

#define ll long long
#define Size(v) (int)v.size()

using namespace std;
// using namespace __gnu_pbds;

const int mod = 1e9 + 7;
const int nax = 105;

struct matrix {
	int a[nax][nax];

	matrix() {
		for (int i = 0; i < nax; ++i) {
			fill(a[i], a[i] + nax, 0);
		}
	}

	int* operator[](int i) {
		return a[i];
	}

	matrix operator*(matrix b) {
		matrix res = matrix();
		for (int i = 1; i < nax; ++i) {
			for (int j = 1; j < nax; ++j) {
				for (int k = 1; k < nax; ++k) {
					res[i][j] = (res[i][j] + a[i][k] * b[k][j]) % mod;
				}
			}
		}
		return res;
	}
};

matrix power(const matrix & f, int n) {
	if (n == 1) return f;

	matrix half = power(f, n / 2);
	matrix out = half * half;

	if (n & 1) out = out * f;

	return out;
}

int m, n;

void set_transition(matrix & T) {
	T[1][m] = 1;
	T[m][m] = 1;
	for (int i = 2; i <= m; ++i) {
		T[i][i - 1] = 1;
	}
}

void solve() {
	cin >> n >> m;

	matrix s = matrix();
	matrix t = matrix();

	for (int i = 1; i < m; ++i) s[1][i] = 1;
	s[1][m] = 2;

	t[1][m] = 1;
	t[m][m] = 1;

	for (int i = 2; i <= m; ++i) t[i][i - 1] = 1;

	matrix res = power(t, n - 1);

	s = s * res; // BIG CAUTION: A * B != B * A

	cout << s[1][1];
}

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int t = 1;
	while (t--)
		solve();
	return 0;
}

#include<bits/stdc++.h>
#define int long long
#define ll long long
#define pb emplace_back
#define mp make_pair
#define tci(v,i) for(auto i=v.begin();i!=v.end();i++)
#define all(v) v.begin(),v.end()
#define rep(i,start,lim) for(long long (i)=(start);i<(lim);i++)
#define revrep(i,n) for(long long i=n-1;i>=0;i--)
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define osit ostream_iterator<int> output (cout," ")
#define pv(x) copy(all(x),output)
#define pa(a) rep(i,0,sizeof(a)/sizeof(a[0]))cout<<a[i]<<" "
#define endl '\n'
#define f first
#define s second
#define PI 3.141592653589793
#define test int t;cin>>t; while(t--)
#define set0(x) memset(x,0,sizeof(x))
#define set1(x) memset(x,1,sizeof(x))
#define getarr(arr,n) int arr[n];rep(i,0,n)cin>>a[i]
#define getvec(vec,n) vi vec;int x;rep(i,0,n){cin>>x;vec.pb(x);}
#define dg(x) cout<<#x<<':'<<x<<endl;
#define dg2(x,y) cout<<#x<<':'<<x<<' '<<#y<<':'<<y<<endl;
#define dg3(x,y,z) cout<<#x<<':'<<x<<' '<<#y<<':'<<y<<' '<<#z<<':'<<z<<endl;
#define dg4(x,y,z,zz) cout<<#x<<':'<<x<<' '<<#y<<':'<<y<<' '<<#z<<':'<<z<<' '<<#zz<<':'<<zz<<endl;
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;
template<typename T> T gcd(T a,T b){if(a==0) return b; return gcd(b%a,a);}
vi b_v;void bin(unsigned int n) { if (n > 1) bin(n>>1); b_v.pb(n & 1); }
int isPowerof2(int x) { return (x && !(x & x-1)); }

const int mod=1e9+7;
int n,m;

void mult(vvi& A, vvi& B){
    int m = A.size();
    vvi C(m, vi(m, 0));
    for(int i=0; i<m; i++){
        for(int j=0; j<m; j++){
            for(int k=0; k<m; k++){
                C[i][j] += A[i][k] * B[k][j];
                C[i][j] %= mod;
            }
        }
    }
    A = C;
}

int32_t main(){
    boost;osit;
    cin>>n>>m;
    n-=2;
    vvi A(m,vi(m,0));
    A[0][0]=1;
    A[0][m-1]=1;
    rep(i,1,m)A[i][i-1]=1;
    vvi X=A;
    while(n>0){
        if(n&1){
            n--;
            mult(A,X);
        }else{
            n/=2;
            mult(A,A);
        }
    }
    rep(i,0,m){
        rep(j,0,m){
            cout<<A[i][j]<<" ";
        }
        cout<<endl;
    }
    int ans=0;
    rep(i,0,m)ans+=A[0][i],ans%=mod;
    cout<<ans;
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

const unsigned long long Mod = 1e9 + 7;

unsigned long long a[105][105], p[105][105], aux[105][105];
unsigned long long n, m;

void inmulteste() {
    memset (aux, 0, sizeof (aux));
    for (int i = 1; i <= m; ++ i) {
        for (int k = 1; k <= m; ++ k) {
            for (int j = 1; j <= m; ++ j) {
                aux[i][k] = aux[i][k] + (p[i][j] * a[j][k]) % Mod;
                aux[i][k] %= Mod;
            }
        }
    }

    for (int i = 1; i <= m; ++ i) {
        for (int j = 1; j <= m; ++ j) {
            p[i][j] = aux[i][j] % Mod;
        }
    }
}

void ridica() {
    memset (aux, 0, sizeof (aux));
    for (int i = 1; i <= m; ++ i) {
        for (int k = 1; k <= m; ++ k) {
            for (int j = 1; j <= m; ++ j) {
                aux[i][k] = aux[i][k] + (a[i][j] * a[j][k]) % Mod;
                aux[i][k] %= Mod;
            }
        }
    }

    for (int i = 1; i <= m; ++ i) {
        for (int j = 1; j <= m; ++ j) {
            a[i][j] = aux[i][j] % Mod;
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    cin >> n >> m;
    if (n < m) {
        cout << 1 << '\n';
    }

    for (int i = 1; i <= m; ++ i) {
        p[1][i] = 1;
    }

    for (int i = 1; i < m; ++ i) {
        a[i + 1][i] = 1;
    }

    a[1][m] = a[m][m] = 1;
    n -= m; ++ n;

    while (n) {
        if (n % 2 == 1) {
            inmulteste();
            --n;
        }

        else {
            ridica();
            n /= 2;
        }
    }

    cout << p[1][m] << '\n';
    return 0;
}

#include <bits/stdc++.h>
#include <ext/numeric>

using namespace std;
using namespace __gnu_cxx;

typedef double db;
typedef long long ll;
typedef pair<db, db> pdd;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef unsigned long long ull;

#define F          first
#define S          second
#define pnl        printf("\n")
#define sz(x)      (int)x.size()
#define sf(x)      scanf("%d",&x)
#define pf(x)      printf("%d\n",x)
#define all(x)     x.begin(),x.end()
#define rall(x)    x.rbegin(),x.rend()
#define rep(i, n)  for(int i = 0; i < n; ++i)

const db eps = 1e-9;
const db pi = acos(-1);
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1000 * 1000 * 1000 + 7;

const int matSiz=102;
const int MOD=1000000007;

struct matrix{
  int mat[matSiz][matSiz];
};

struct MUL{
  matrix operator()(const matrix &a,const matrix &b)const{
    matrix res;
    for(int i=0;i<matSiz;++i)
      for(int j=0;j<matSiz;++j){
        res.mat[i][j]=0;
        for(int k=0;k<matSiz;++k){
          ll tmp=a.mat[i][k]*1LL*b.mat[k][j];
          if(tmp>=MOD)tmp%=MOD;
          res.mat[i][j]+=tmp;
          if(res.mat[i][j]>=MOD)
            res.mat[i][j]-=MOD;
        }
      }
    return res;
  }
};

matrix identity_element(const MUL &){
  matrix res;
  for(int i=0;i<matSiz;++i)
    for(int j=0;j<matSiz;++j)
      res.mat[i][j]=(i==j);
  return res;
}

ll n, m;

int main() {
    cin >> n >> m;
    MUL mul;
    matrix A, B;
    memset(A.mat, 0, sizeof A.mat);
    memset(B.mat, 0, sizeof B.mat);
    A.mat[0][0] = 1;
    A.mat[0][m] = 1;
    A.mat[0][101] = 1;
    for (int i = 1; i <= 100; ++i)
    	A.mat[i][i - 1] = 1;
    A.mat[101][101] = 1;
    A = power(A, n - 1, mul);
    B.mat[0][0] = 1;
    B.mat[101][0] = 1;
    B = mul(A, B);
    cout << B.mat[0][0] << endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
typedef long long ll;
ll n, m;
int trix[102][102], ans[102][102];

void prod(int (*p1)[102], int(*p2)[102], int (*p3)[102]){
  int aux[102][102];
  for(int i=1; i<=m; i++){
    for(int j=1; j<=m; j++){
      int sum=0;
      for(int k=1; k<=m; k++){
        sum+=p1[i][k]*p2[k][j];
      }
      aux[i][j]=sum;
    }
  }
  for(int i=1; i<=m; i++){
    for(int j=1; j<=m; j++){
      p3[i][j]=aux[i][j];
    }
  }
}

void identidade(int (*p)[102]){
  for(int i=1; i<=m; i++){
    for(int j=1; j<=m; j++){
      p[i][j]=(i==j);
    }
  }
}
void start_matrix(int (*p)[102]){
  p[1][1]=p[1][m]=1;
  for(int i=2; i<=m; i++){
    p[i][i-1]=1;
  }
}
void fast_exp(int (*p)[102], int (*ans)[102], ll e){
  identidade(ans);
  while(e){
    if(e&1) prod(ans, p, ans);
    e/=2;
    prod(p, p, p);
  }
}

void print(int (*p)[102]){
  for(int i=1; i<=m; i++){
    for(int j=1; j<=m; j++){
      printf("%d\t", p[i][j]);
    }
    printf("\n");
  }
}
int main(){
  scanf("%lld %lld", &n, &m);
  start_matrix(trix);
  fast_exp(trix, ans, n-m);
  // print(ans);
  ll resp=(2*ans[1][1])%(mod);
  for(int i=2; i<=m; i++){
    resp=(resp+ans[1][i])%(mod);
  }
  printf("%d\n", resp);
}

////////////////////////////////////////////
///                                      ///
///         Template ver. 1 rapel        ///
/// Fear is Temporary, Regret is Forever ///
///          Must Try and Get AC         ///
///                                      ///
////////////////////////////////////////////
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <iomanip>

#include <algorithm>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>

#include <math.h>
#include <complex>

#include <assert.h>
#include <time.h>
//#include <chrono>
//#include <random>

#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <bitset>

#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define endl '\n'
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;

void desperate_optimization(int precision){
  	ios_base::sync_with_stdio(false);
  	cin.tie(0);
  	cout.tie(0);
  	cout.setf(ios::fixed);
  	cout.setf(ios::showpoint);
  	cout.precision(precision);
}

const LL MOD = 1e9 + 7;

struct matrix{
	LL arr[2][2];
};

matrix mulmat(matrix &A,matrix &B) {
	matrix C;
	for(int i = 0;i < 2;i++) {
		for(int j = 0;j < 2;j++) {
			C.arr[i][j] = 0;
			for(int k = 0;k < 2;k++) {
				C.arr[i][j] = (C.arr[i][j] + A.arr[i][k] * B.arr[k][j]) % MOD;
			}
		}
	}
	return C;
}

LL fast(LL x) {
	if(x <= 0) return 1;
	matrix base, ans;
	for(int i = 0;i < 2;i++) {
		for(int j = 0;j < 2;j++) {
			ans.arr[i][j] = ((i == j)?1:0);
			base.arr[i][j] = 1;
		}
	}
	base.arr[1][1] = 0;
	while(x) {
		if(x & 1) ans = mulmat(ans,base);
		base = mulmat(base,base);
		x /= 2;
	}
	return (ans.arr[0][0] + ans.arr[0][1]) % MOD;
}

void hora(int tc) {
	LL n,m;
	cin>>n>>m;
	LL tot = n + 2 - m;
	cout<<fast(tot - 1)<<endl;
}

int main(){
	desperate_optimization(10);
	int ntc = 1;
	//cin>>ntc;
	for(int tc = 1;tc <= ntc;tc++) hora(tc);
	return 0;
}

// Author: Tyler Wang

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <climits>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <optional>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string_view>
#include <tuple>
#include <type_traits>
#include <utility>
#include <vector>

using namespace std;

template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, const std::pair<T1, T2>& p) {
  return os << '{' << p.first << ", " << p.second << '}';
}

template <
    typename Container, typename = typename Container::const_iterator,
    typename = std::enable_if_t<!std::is_same_v<Container, std::string> &&
                                !std::is_same_v<Container, std::string_view>>>
std::ostream& operator<<(std::ostream& os, const Container& x) {
  os << '{';
  for (auto it = x.begin(); it != x.end(); ++it) {
    if (it != x.begin()) {
      os << ", ";
    }
    os << *it;
  }
  return os << '}';
}

template <typename T>
void debug_impl(std::string_view name, const T& val) {
  std::cerr << name << " = " << val << std::endl;
}

template <typename T1, typename... Ts>
void debug_impl(std::string_view names, const T1& val1, const Ts&... vals) {
  for (int i = 0, paren = 0; i < names.size(); ++i) {
    if (names[i] == '(' || names[i] == '{') {
      ++paren;
    } else if (names[i] == ')' || names[i] == '}') {
      --paren;
    } else if (names[i] == ',' && paren == 0) {
      std::cerr << names.substr(0, i) << " = " << val1 << ',';
      return debug_impl(names.substr(i + 1), vals...);
    }
  }
}

#ifdef TYLER
#define debug(...) debug_impl(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) ((void)0)
#endif

template <int Mod = 1'000'000'007>
class mod_int {
 public:
  constexpr mod_int() : data_(0) {}

  template <typename T, typename = std::enable_if_t<std::is_integral_v<T>>>
  constexpr mod_int(T val) : data_(val % Mod) {
    if (data_ < 0) {
      data_ += Mod;
    }
  }

  template <typename T, typename = std::enable_if_t<std::is_integral_v<T>>>
  constexpr explicit operator T() const {
    return data_;
  }

  constexpr mod_int operator++() {
    if (++data_ == Mod) {
      data_ = 0;
    }
    return *this;
  }

  constexpr mod_int operator++(int) {
    mod_int t = *this;
    ++*this;
    return t;
  }

  constexpr mod_int operator--() {
    if (data_ == 0) {
      data_ = Mod;
    }
    --data_;
    return *this;
  }

  constexpr mod_int operator--(int) {
    mod_int t = *this;
    --*this;
    return t;
  }

  constexpr mod_int operator+=(mod_int other) {
    if ((data_ += other.data_) >= Mod) {
      data_ -= Mod;
    }
    return *this;
  }

  constexpr mod_int operator-=(mod_int other) {
    if ((data_ -= other.data_) < 0) {
      data_ += Mod;
    }
    return *this;
  }

  constexpr mod_int operator*=(mod_int other) {
    data_ = (long long)data_ * other.data_ % Mod;
    return *this;
  }

  constexpr mod_int operator/=(mod_int other) { return *this *= inv(other); }

  friend constexpr mod_int operator-(mod_int mi) {
    if (mi.data_ != 0) {
      mi.data_ = Mod - mi.data_;
    }
    return mi;
  }

  friend constexpr mod_int operator+(mod_int lhs, mod_int rhs) {
    return lhs += rhs;
  }

  friend constexpr mod_int operator-(mod_int lhs, mod_int rhs) {
    return lhs -= rhs;
  }

  friend constexpr mod_int operator*(mod_int lhs, mod_int rhs) {
    return lhs *= rhs;
  }

  friend constexpr mod_int operator/(mod_int lhs, mod_int rhs) {
    return lhs /= rhs;
  }

  friend constexpr bool operator==(mod_int lhs, mod_int rhs) {
    return lhs.data_ == rhs.data_;
  }

  friend constexpr bool operator!=(mod_int lhs, mod_int rhs) {
    return lhs.data_ != rhs.data_;
  }

  friend constexpr bool operator<(mod_int lhs, mod_int rhs) {
    return lhs.data_ < rhs.data_;
  }

  friend constexpr bool operator<=(mod_int lhs, mod_int rhs) {
    return lhs.data_ <= rhs.data_;
  }

  friend constexpr bool operator>(mod_int lhs, mod_int rhs) {
    return lhs.data_ > rhs.data_;
  }

  friend constexpr bool operator>=(mod_int lhs, mod_int rhs) {
    return lhs.data_ >= rhs.data_;
  }

  friend std::ostream& operator<<(std::ostream& os, mod_int mi) {
    return os << mi.data_;
  }

  friend std::istream& operator>>(std::istream& is, mod_int& mi) {
    long long val;
    is >> val;
    mi = mod_int(val);
    return is;
  }

  friend constexpr mod_int inv(mod_int mi) {
    int a = mi.data_, b = Mod;
    int x = 0, xx = 1;
    while (a != 0) {
      int q = b / a;
      int t = a;
      a = b - q * a;
      b = t;
      t = xx;
      xx = x - q * xx;
      x = t;
    }
    return mod_int(x);
  }

  template <typename T, typename = std::enable_if_t<std::is_integral_v<T>>>
  friend constexpr mod_int pow(mod_int base, T expo) {
    if (expo < 0) {
      return pow(inv(base), -expo);
    }
    mod_int res = 1;
    for (; expo != 0; expo >>= 1) {
      if (expo & 1) {
        res *= base;
      }
      base *= base;
    }
    return res;
  }

 private:
  int data_;
};

mod_int<> choose(int n, int k) {
  mod_int<> ans = 1;
  for (int i = n; i > n - k; --i) {
    ans *= mod_int(i);
  }
  for (int i = 2; i <= k; ++i) {
    ans /= mod_int(i);
  }
  return ans;
}

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cerr << std::boolalpha;
  std::mt19937 rng(
      std::chrono::high_resolution_clock::now().time_since_epoch().count());
  long long long_n;
  int m;
  cin >> long_n >> m;
  int n = long_n % 1'000'000'007;
  mod_int<> ans = 1;
  for (int i = 1; i * m <= n; ++i) {
    ans += choose(n - i * m + i, i);
  }
  cout << ans << '\n';
  return 0;
}