#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int MAXN = 100;
struct mtx {
  int d[MAXN][MAXN];
  int r, c;
};
mtx operator*(const mtx l, const mtx r) {
  mtx res;
  res.r = l.r;
  res.c = r.c;
  assert(l.c == r.r);
  for (int i = 0; i < res.r; i++)
    for (int j = 0; j < res.c; j++) {
      int sm = 0;
      for (int k = 0; k < l.c; k++) {
        sm += 1ll * l.d[i][k] * r.d[k][j] % mod;
        sm %= mod;
      }
      res.d[i][j] = sm;
    }
  return res;
}
void idmtx(mtx &m) {
  assert(m.r == m.c);
  for (int i = 0; i < m.r; i++) {
    for (int j = 0; j < m.c; j++) {
      m.d[i][j] = i == j;
    }
  }
}
mtx mtxpow(const mtx m, long long p) {
  mtx r;
  r.r = r.c = m.r;
  idmtx(r);
  mtx c = m;
  for (; p; p >>= 1) {
    if (p & 1) r = r * c;
    c = c * c;
  }
  return r;
}
void printmtx(const mtx m) {
  cout << "MTX ---- " << endl;
  for (int i = 0; i < m.r; i++) {
    for (int j = 0; j < m.c; j++) {
      cout << m.d[i][j] << " ";
    }
    cout << endl;
  }
}
int main() {
  long long n;
  int m;
  cin >> n >> m;
  mtx rm;
  rm.r = rm.c = m;
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < m; j++) {
      rm.d[i][j] = 0;
      if (i == j) rm.d[i][j] += 1;
      if (j == 0) {
        rm.d[i][j] += i == m - 1 ? 1 : 0;
      } else {
        rm.d[i][j] += rm.d[i][j - 1];
      }
      rm.d[i][j] %= mod;
    }
  }
  long long off = (n - 1) % m, k = (n - 1) / m;
  mtx res = mtxpow(rm, k + 1);
  cout << res.d[m - 1][off] << endl;
  return 0;
}
