#include <bits/stdc++.h>
using namespace std;
template <typename T>
struct Matrix {
  T mat[128][128];
  static int sz, mod;
  Matrix() {}
  Matrix(const T &x) {
    int i;
    memset(mat, 0, sizeof(mat));
    for (i = 0; i < sz; ++i) mat[i][i] = x;
  }
  static int size() { return sz; }
  static void resize(int n) { sz = n; }
  static void setMod(int p) { mod = p; }
  T *operator[](int k) { return mat[k]; }
  Matrix operator*(const Matrix &o) const {
    Matrix ret(0);
    int i, j, k;
    for (i = 0; i < sz; ++i) {
      for (k = 0; k < sz; ++k) {
        if (!mat[i][k]) continue;
        for (j = 0; j < sz; ++j) {
          ret.mat[i][j] += mat[i][k] * o.mat[k][j];
          if (~mod) ret.mat[i][j] %= mod;
        }
      }
    }
    return ret;
  }
  Matrix pow(long long n) const {
    Matrix ret(1), a = *this;
    for (; n; n >>= 1) {
      if (n & 1) ret = ret * a;
      a = a * a;
    }
    return ret;
  }
};
template <typename T>
int Matrix<T>::sz = 0;
template <typename T>
int Matrix<T>::mod = -1;
long long cb[128][128], vec[128];
long long calc(int n, int k) {
  if (!k || n == k) return 1;
  if (~cb[n][k]) return cb[n][k];
  return cb[n][k] = (calc(n - 1, k - 1) + calc(n - 1, k)) % 1000000007;
}
long long solve(long long n, int k) {
  Matrix<long long> a(0), b;
  int i, j, m = (2 * (k + 1) + 1);
  long long ret = 0;
  Matrix<long long>::resize(m);
  Matrix<long long>::setMod(1000000007);
  a[0][0] = a[0][1] = 1;
  for (i = 0; i <= k; ++i) {
    for (j = i; j <= k; ++j) {
      a[(((i) << 1) + 1)][(((j) << 1) + 1)] = calc(k - i, j - i);
      a[(((i) << 1) + 1)][(((j) << 1) + 2)] = calc(k - i, j - i);
      a[(((i) << 1) + 2)][(((j) << 1) + 1)] = calc(k - i, j - i);
      a[(((i) << 1) + 2)][(((j) << 1) + 2)] = 0;
    }
  }
  b = a.pow(n);
  vec[0] = 0;
  for (i = 1; i < m; ++i) vec[i] = 1;
  for (i = 0; i < m; ++i) {
    ret = (ret + b[0][i] * vec[i]) % 1000000007;
  }
  return ret;
}
int main() {
  long long n;
  int k;
  memset(cb, -1, sizeof(cb));
  while (cin >> n >> k) {
    cout << solve(n, k) << endl;
  }
  return 0;
}
