#include <bits/stdc++.h>
using namespace std;
const long long mxn = 1e3 + 10;
const long long inf = 1e9;
const long long mod = 1e9 + 7;
long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; }
long long n, m;
map<long long, long long> mp;
long long dp(long long n) {
  if (n < 0) return 0;
  if (n < m) {
    mp[n] = 1;
    return 1;
  }
  if (mp.find(n) != mp.end()) return mp[n];
  long long mid = n / 2;
  long long ans = 0;
  for (int i = 1; i < m; i++) {
    ans = (ans + (dp(mid - i) * dp(n - mid + i - m)) % mod) % mod;
  }
  ans = (ans + (dp(mid) * dp(n - mid)) % mod) % mod;
  mp[n] = ans;
  return ans;
}
int main() {
  cin >> n >> m;
  cout << dp(n) << endl;
  return 0;
}
