#include <bits/stdc++.h>
using namespace std;
const int m = 1000000007;
long long N, M;
map<long long, long long> dp;
long long compute(long long x) {
  if (x < 0) return 0;
  if (x < M) return 1;
  if (dp.find(x) == dp.end()) {
    long long res = (compute(x / 2) * compute((x + 1) / 2)) % m;
    for (int i = 1; i < M; ++i) {
      res += compute(x / 2 - i) * compute((x + 1) / 2 - (M - i));
      res %= m;
    }
    dp[x] = res;
  }
  return dp[x];
}
int main() {
  ios_base::sync_with_stdio(false);
  cout << setprecision(12) << fixed;
  cin >> N >> M;
  cout << compute(N) << endl;
  return 0;
}
