#include <bits/stdc++.h>
using namespace std;
long long int n;
int m;
long long int matrix[1 << 7][101][101];
void multiply(int a, int b, int c) {
  for (int i = 0; i < m; i++)
    for (int j = 0; j < m; j++)
      for (int k = 0; k < m; k++)
        matrix[c][i][j] = (matrix[c][i][j] +
                           ((matrix[a][i][k] * matrix[b][k][j]) % 1000000007)) %
                          1000000007;
}
int mpow(long long int pow) {
  if (pow == 1) return 1;
  long long int half = pow / 2;
  int pi = mpow(half);
  multiply(pi, pi, pi + 1);
  if (pow % 2) multiply(pi + 1, 1, pi + 2);
  return pi + 1 + (pow % 2);
}
void solve() {
  scanf("%lli %d", &n, &m);
  if (n < m)
    printf("1");
  else if (n == m)
    printf("2");
  else {
    memset(matrix, 0, sizeof(matrix));
    matrix[1][0][0] = matrix[1][0][m - 1] = 1;
    matrix[0][0][0] = 2;
    for (int i = 1; i < m; i++) matrix[1][i][i - 1] = 1;
    for (int i = 1; i < m; i++) matrix[0][i][0] = 1;
    int pi = mpow(n - m);
    multiply(pi, 0, pi + 1);
    printf("%lli", matrix[pi + 1][0][0]);
  }
}
int main() { solve(); }
