#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
#define int long long int
const int INF = 1001001001001001LL;
const int MOD = 1000000007;

int modpow(int a, int n){
    int ret = 1;
    while(n > 0){
        if(n & 1) ret = ret * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }

    return ret;
}

signed main(){
    
    int n, m; cin >> n >> m;
    if(n == m){
        cout << 1 << endl;
        return 0;
    }
    int ans = modpow(2, n);
    vector<int> dp(n + 1, 0);
    dp[0] = 1;
    for(int i = 1; i <= n; i++){
        int l = max(0LL, i - m);
        int r = i - 1;
        int add;
        if(l == 0) add = dp[r];
        else add = (dp[r] - dp[l - 1] + MOD) % MOD;
        dp[i] += add;
        dp[i] %= MOD;
        dp[i] += dp[i - 1];
        dp[i] %= MOD;
    }
    
    //for(int i = 0; i <= n; i++) cout << dp[i] << " ";
    //cout << endl;

    int sub = 0;
    for(int i = n - m + 1; i <= n; i++){
        //cout << i << endl;
        sub = (MOD + sub + (dp[i] - dp[i - 1])) % MOD;
        sub %= MOD;
    }
    //cout << sub << endl;
    cout << (ans - sub + MOD) % MOD << endl;

    return 0;
}

