#include <bits/stdc++.h>
using namespace std;
const int M = 1e9 + 7;
long long n, m;
struct Mat {
  long long a[102][102];
};
Mat mul(const Mat& a, const Mat& b) {
  Mat ans;
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= m; j++) {
      ans.a[i][j] = 0;
      for (int k = 1; k <= m; k++) {
        ans.a[i][j] += a.a[i][k] * b.a[k][j];
        if (ans.a[i][j] > M) ans.a[i][j] %= M;
      }
    }
  }
  return ans;
}
Mat quick_pow(Mat a, long long b) {
  Mat t;
  for (int i = 1; i <= m; i++) t.a[i][i] = 1;
  while (b) {
    if (b & 1) t = mul(t, a);
    b >>= 1;
    a = mul(a, a);
  }
  return t;
}
int main() {
  cin >> n >> m;
  if (n < m) {
    cout << 1 << endl;
  } else {
    Mat ans, t;
    for (int i = 1; i < m; i++) {
      ans.a[i + 1][i] = 1;
    }
    ans.a[1][m] = ans.a[m][m] = 1;
    ans = quick_pow(ans, n - m);
    Mat a;
    for (int i = 1; i < m; i++) a.a[1][i] = 1;
    a.a[1][m] = 2;
    a = mul(a, ans);
    cout << a.a[1][m] << endl;
  }
  return 0;
}
