#include <bits/stdc++.h>
using namespace std;
const int maxn = (2 * 40) + 4, mod = 1e9 + 7, LOG = 60;
int k, poww[maxn], intk[maxn][maxn];
long long n;
struct matrix {
  int mat[maxn][maxn];
  int n;
  int m;
  matrix(int a, int b) {
    n = a;
    m = b;
    for (int i = 0; i < maxn; i++) {
      for (int j = 0; j < maxn; j++) {
        mat[i][j] = 0;
      }
    }
  }
  int* operator[](int x) { return mat[x]; }
};
matrix operator*(matrix a, matrix b) {
  matrix res(a.n, b.m);
  for (int i = 0; i < res.n; i++) {
    for (int k = 0; k < a.m; k++) {
      for (int j = 0; j < res.m; j++) {
        res[i][j] = (res[i][j] + (1ll * a[i][k] * b[k][j])) % mod;
      }
    }
  }
  return res;
}
matrix Identity(int x) {
  matrix res(x, x);
  for (int i = 0; i < x; i++) {
    res[i][i] = 1;
  }
  return res;
}
matrix operator^(matrix a, long long b) {
  matrix res = Identity(a.n);
  matrix tmp = a;
  for (int i = 0; i <= LOG; i++) {
    if ((1ll << i) & b) {
      res = res * tmp;
    }
    if ((1ll << i) >= b) {
      break;
    }
    tmp = tmp * tmp;
  }
  return res;
}
void prepare() {
  for (int i = 0; i <= k; i++) {
    for (int j = 0; j <= i; j++) {
      if (j == 0 || j == i) {
        intk[i][j] = 1;
        continue;
      }
      intk[i][j] = (intk[i - 1][j - 1] + intk[i - 1][j]) % mod;
    }
  }
  return;
}
void chap(matrix t) {
  for (int i = 0; i < t.n; i++) {
    for (int j = 0; j < t.m; j++) {
      cout << t[i][j] << " ";
    }
    cout << endl;
  }
}
int main() {
  cin >> n >> k;
  prepare();
  matrix p(2 * k + 3, 2 * k + 3);
  matrix ans(1, 2 * k + 3);
  poww[0] = 1;
  for (int i = 1; i <= k + 1; i++) {
    poww[i] = (poww[i - 1] * 2) % mod;
  }
  for (int i = 0; i <= k; i++) {
    ans[0][i] = poww[k - i + 1];
  }
  for (int i = k + 1; i <= 2 * k + 1; i++) {
    ans[0][i] = 1;
  }
  ans[0][2 * k + 2] = 1;
  for (int i = 0; i <= k; i++) {
    for (int j = 0; j <= i; j++) {
      p[i][j] = intk[k - j][k - i];
    }
  }
  for (int i = k + 1; i <= 2 * k + 1; i++) {
    for (int j = 0; j <= (i - k - 1); j++) {
      p[i][j] = (1ll * intk[k - j][k - (i - k - 1)] *
                 poww[k - j - (k - (i - k - 1))]) %
                mod;
    }
  }
  for (int i = k + 1; i <= 2 * k + 1; i++) {
    p[i - k - 1][i] = 1;
  }
  p[0][2 * k + 2] = 1;
  p[2 * k + 2][2 * k + 2] = 1;
  p = p ^ (n - 1);
  ans = ans * p;
  cout << ans[0][2 * k + 2] << endl;
  return 0;
}
