#include <bits/stdc++.h>
using namespace std;
struct mat {
  long long data[105][105];
  long long row, col;
  mat copy_mat() {
    mat ret;
    ret.row = row;
    ret.col = col;
    for (int i = 0; i < row; i++) {
      for (int j = 0; j < col; j++) ret.data[i][j] = data[i][j];
    }
    return ret;
  }
};
mat getIdentity(int n) {
  mat ret;
  memset(ret.data, 0, sizeof(ret.data));
  ret.row = ret.col = n;
  for (int i = 0; i < n; i++) ret.data[i][i] = 1;
  return ret;
}
struct mat F, I;
const long long MOD = 1000000007;
long long dp_mat[105][105];
struct mat multiply(struct mat A, struct mat B) {
  struct mat C;
  if (A.col != B.row) return C;
  C.row = A.row;
  C.col = B.col;
  for (int i = 0; i < C.row; i++) {
    for (int j = 0; j < C.col; j++) {
      C.data[i][j] = 0;
      for (int k = 0; k < A.col; k++)
        C.data[i][j] =
            (C.data[i][j] + (A.data[i][k] * B.data[k][j]) % MOD) % MOD;
    }
  }
  return C;
}
struct mat power(struct mat A, long long p) {
  struct mat ret = getIdentity(A.row);
  struct mat curr = A.copy_mat();
  while (p) {
    if (p & 1) ret = multiply(ret, curr);
    p >>= 1;
    curr = multiply(curr, curr);
  }
  return ret;
}
int main() {
  long long n, m;
  scanf("%lld %lld", &n, &m);
  I.row = I.col = m;
  memset(I.data, 0, sizeof(I.data));
  I.data[0][0] = 1;
  I.data[0][m - 1] = 1;
  for (int i = 1; i < I.row; i++) {
    I.data[i][i - 1] = 1;
  }
  struct mat ans = power(I, n);
  printf("%lld\n", ans.data[0][0]);
  return 0;
}
