#include <bits/stdc++.h>
using namespace std;
long long n, k, x[100000], c[100000];
vector<long long> mul(vector<long long> a, vector<long long> b) {
  vector<long long> ans(n + n + 1);
  for (long long i = 1; i < n + 1; ++i)
    for (long long j = 1; j < n + 1; ++j)
      ans[i + j] = (ans[i + j] + (a[i] * b[j])) % 1000000007LL;
  for (long long i = n + n; i >= n + 1; --i) {
    for (long long j = 1; j < n + 1; ++j)
      ans[i - j] = (ans[i - j] + ans[i] * c[j]) % 1000000007LL;
    ans[i] = 0;
  }
  return ans;
}
vector<long long> ppow(vector<long long> a, long long k) {
  if (k == 1) return a;
  if (k % 2 == 0) return ppow(mul(a, a), k >> 1);
  if (k % 2 == 1) return mul(ppow(mul(a, a), k >> 1), a);
}
long long nn, mm;
int32_t main() {
  cin.tie(0), cout.sync_with_stdio(0);
  cin >> nn >> mm;
  if (nn < mm)
    cout << 1 << "\n";
  else if (nn < mm + mm)
    cout << nn - mm + 2 << "\n";
  else {
    n = mm + mm - 2;
    for (long long i = 1; i < n + 1; ++i) x[i] = i < mm ? 1 : i - mm + 2;
    for (long long i = 1; i < n + 1; ++i)
      if (i <= mm) c[n + 1 - i] = 1;
    vector<long long> v(n + n + 1);
    v[1] = 1;
    v = ppow(v, nn);
    long long ans = 0;
    for (long long i = 1; i < n + 1; ++i)
      ans = (ans + x[i] * v[i]) % 1000000007LL;
    cout << ans << "\n";
  }
  return 0;
}
