#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int len;
long long n, k;
long long c[45][45];
struct matrix {
  long long m[100][100];
} mc, I;
matrix multi(matrix a, matrix b) {
  matrix ans;
  for (int i = 0; i < len; i++) {
    for (int j = 0; j < len; j++) {
      ans.m[i][j] = 0;
      for (int k = 0; k < len; k++) {
        ans.m[i][j] = (ans.m[i][j] + a.m[i][k] * b.m[k][j]) % mod;
      }
    }
  }
  return ans;
}
matrix quick(matrix a, long long n) {
  matrix ans = I, t = a;
  while (n > 0) {
    if (n & 1) ans = multi(ans, t);
    t = multi(t, t);
    n >>= 1;
  }
  return ans;
}
int main() {
  c[0][0] = 1;
  c[1][0] = c[1][1] = 1;
  for (int i = 2; i <= 40; i++) {
    for (int j = 0; j <= i; j++) {
      if (j == 0 || j == i)
        c[i][j] = 1;
      else
        c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % mod;
    }
  }
  for (int i = 0; i <= 40; i++) {
    I.m[i][i] = 1;
  }
  cin >> n >> k;
  memset(mc.m, 0, sizeof(mc.m));
  len = 2 * k + 3;
  mc.m[0][0] = 1;
  for (int j = 0; j <= k; j++) {
    mc.m[0][j + 1] = c[k][j];
    mc.m[0][j + k + 2] = c[k][j];
  }
  for (int i = 0; i <= k; i++) {
    for (int j = 0; j <= i; j++) {
      mc.m[i + 1][j + 1] = c[i][j];
      mc.m[i + 1][j + k + 2] = c[i][j];
    }
  }
  for (int i = 0; i <= k; i++) {
    for (int j = 0; j <= i; j++) {
      mc.m[i + k + 2][j + 1] = c[i][j];
    }
  }
  mc = quick(mc, n - 1);
  long long ans = 0;
  for (int i = 0; i < len; i++) {
    ans = (ans + mc.m[0][i]) % mod;
  }
  printf("%d\n", ans);
  return 0;
}
