#include <bits/stdc++.h>
using namespace std;
const int sz = 105;
long long int r[sz], a[sz][sz], b[sz][sz], ans[sz][sz], m;
void multiply(long long int a[][sz], long long int b[][sz]) {
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < m; j++) {
      ans[i][j] = 0;
      for (int k = 0; k < m; k++) {
        ans[i][j] += a[i][k] * b[k][j] % 1000000007;
        ans[i][j] %= 1000000007;
      }
    }
  }
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < m; j++) {
      a[i][j] = ans[i][j];
    }
  }
}
void power(long long int a[][sz], long long int n) {
  if (n <= 1) {
    return;
  }
  power(a, n / 2);
  multiply(a, a);
  if (n % 2 == 1) {
    multiply(a, b);
  }
}
int main() {
  long long int n;
  cin >> n >> m;
  r[0] = 1;
  for (int i = 1; i <= m; i++) {
    r[i] = r[i - 1];
    if (i - m >= 0) {
      r[i] += r[i - m];
    }
    r[i] %= 1000000007;
  }
  for (int i = 1; i < m; i++) {
    a[i][i - 1] = b[i][i - 1] = 1;
  }
  a[0][m - 1] = b[0][m - 1] = 1;
  a[m - 1][m - 1] = b[m - 1][m - 1] = 1;
  power(a, n);
  long long int res = 0;
  for (int k = 0; k < m; k++) {
    res += r[k] * a[k][0] % 1000000007;
    res %= 1000000007;
  }
  cout << res << endl;
  return 0;
}
