#include <bits/stdc++.h>
const int maxk = 41, maxl = maxk * 2 + 1;
const long long mo = 1e9 + 7;
struct mat {
  long long a[maxl][maxl];
  void clear() { memset(a, 0, sizeof(a)); }
  mat operator*(const mat &t) const {
    mat ans;
    ans.clear();
    for (int i = 0; i < maxl; ++i)
      for (int j = 0; j < maxl; ++j)
        for (int k = 0; k < maxl; ++k) {
          ans.a[i][j] = (ans.a[i][j] + a[i][k] * t.a[k][j]) % mo;
        }
    return ans;
  }
} trans;
long long mpow(long long a, long long k) {
  long long ans = 1;
  for (; k > 0; k /= 2, a = a * a % mo)
    if (k % 2) ans = ans * a % mo;
  return ans;
}
mat mpow(mat a, long long k) {
  mat ans;
  ans.clear();
  for (int i = 0; i < maxl; ++i) ans.a[i][i] = 1;
  for (; k > 0; k /= 2, a = a * a)
    if (k % 2) ans = ans * a;
  return ans;
}
long long N, K, c[maxk + 1][maxk + 1];
void initC() {
  for (int i = 0; i <= maxk; ++i) c[i][i] = c[i][0] = 1;
  for (int i = 1; i <= maxk; ++i)
    for (int j = 1; j < i; ++j) c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mo;
}
void initTrans() {
  auto &a = trans.a;
  for (int i = 0; i < maxk; ++i) a[i][i + maxk] = 1;
  for (int i = 0; i < maxk; ++i) {
    for (int j = 0; j <= i; ++j) {
      a[i + maxk][j + maxk] = c[i][j];
      a[i + maxk][j] = c[i][j] * mpow(2, i - j) % mo;
    }
  }
  memcpy(a[maxl - 1], a[maxk + K], sizeof(a[maxl - 1]));
  a[maxl - 1][maxl - 1] = (a[maxl - 1][maxl - 1] + 1) % mo;
}
long long row[maxl];
long long geneAns(const mat &final) {
  row[maxk] = 1;
  long long ans = 0;
  for (int i = 0; i < maxl; ++i)
    ans = (ans + final.a[maxl - 1][i] * row[i]) % mo;
  return ans;
}
int main() {
  scanf("%lld%lld", &N, &K);
  initC();
  initTrans();
  mat final = mpow(trans, N);
  printf("%lld\n", (geneAns(final) + mo) % mo);
  return 0;
}
