#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <string>
#include <string.h>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <numeric>
#include <cctype>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rrep(i,n) for(int i = 1; i <= n; ++i)
#define drep(i,n) for(int i = n-1; i >= 0; --i)
#define gep(i,g,j) for(int i = g.head[j]; i != -1; i = g.e[i].next)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcount
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define df(x) int x = in()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
inline int in() { int x; scanf("%d",&x); return x;}
inline void priv(vi a) { rep(i,sz(a)) printf("%d%c",a[i],i==sz(a)-1?'\n':' ');}
const int MX = 100005, INF = 1000010000;
const ll LINF = 1000000000000000000ll;
const double eps = 1e-10;
// Mod int
int mod;
struct mint{
ll x;
mint():x(0){}
mint(ll x):x((x%mod+mod)%mod){}
mint operator+=(const mint& a){ if((x+=a.x)>=mod) x-=mod; return *this;}
mint operator-=(const mint& a){ if((x+=mod-a.x)>=mod) x-=mod; return *this;}
mint operator*=(const mint& a){ (x*=a.x)%=mod; return *this;}
mint operator+(const mint& a)const{ return mint(*this) += a;}
mint operator-(const mint& a)const{ return mint(*this) -= a;}
mint operator*(const mint& a)const{ return mint(*this) *= a;}
bool operator==(const mint& a)const{ return x == a.x;}
};
//
map<vi,int> mp;
vvi pm;
vvi to;
void genst() {
vi a(4);
rep(i,4) a[i] = i;
queue<vi> q;
mp[a] = 0;
pm = vvi(15);
pm[0] = a;
to = vvi(15,vi(1<<4));
q.push(a);
while(sz(q)) {
a = q.front(); q.pop();
// priv(a);
int v = mp[a];
rep(i,1<<4) {
vi b(4);
rep(j,4) b[j] = j;
rep(j,4)rep(k,j) if ((i>>j&1) && (i>>k&1)) {
int xj = a[j];
int xk = a[k];
if (xj > xk) swap(xj,xk);
// b[xk] = xj;
mins(b[xk],xj);
}
vi c = a;
rep(j,4) c[j] = b[c[j]];
rep(j,4) b[j] = -1;
int cnt = 0;
rep(j,4) {
if (b[c[j]] != -1) continue;
b[c[j]] = cnt++;
}
rep(j,4) c[j] = b[c[j]];
int u = 0;
if (mp.count(c)) {
u = mp[c];
} else {
u = sz(mp);
mp[c] = u;
pm[u] = c;
q.push(c);
}
to[v][i] = u;
}
}
}
mint dp[11][15][1<<4][5][90][1<<4];
int main() {
int n;
scanf("%d%d",&n,&mod);
genst();
// cout<<sz(mp)<<endl;
dp[0][0][0][0][0][0] = 1;
rep(i,10)rep(j,15)rep(k,1<<4)rep(l,3)rep(h,77)rep(u,1<<4) {
mint x = dp[i][j][k][l][h][u];
if (x.x == 0) continue;
int ni = i+1;
rep(f,1<<4)rep(g,1<<4) {
if (i == 0 && g != f) continue;
if ((g&f) != g) continue;
mint p = 1;
if (i) rep(r,4) if(g>>r&1) p *= 2;
int nj = to[j][f];
int nk = k^g;
int nl = l+pcnt(g)%2;
int nh = h+pcnt(f)*2-pcnt(g);
int nu = u|f;
dp[ni][nj][nk][nl][nh][nu] += x*p;
// cout<<i<<" "<<j<<" "<<k<<" "<<l<<" "<<h<<" "<<u<<" "<<f<<" "<<g<<endl;
// cout<<ni<<" "<<nj<<" "<<nk<<" "<<nl<<" "<<nh<<" "<<nu<<" "<<x.x<<" "<<p.x<<endl;
}
}
mint ans = 0;
rep(j,15)rep(k,1<<4)rep(l,3)rep(u,1<<4) {
if (pcnt(k)+l > 2) continue;
vi a = pm[j];
set<int> s;
rep(i,4) if (u>>i&1) s.insert(a[i]);
if (sz(s) == 1) ans += dp[10][j][k][l][n][u];
}
cout<<ans.x<<endl;
return 0;
}
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s9IGE7fQogIG1pbnQgb3BlcmF0b3ItKGNvbnN0IG1pbnQmIGEpY29uc3R7IHJldHVybiBtaW50KCp0aGlzKSAtPSBhO30KICBtaW50IG9wZXJhdG9yKihjb25zdCBtaW50JiBhKWNvbnN0eyByZXR1cm4gbWludCgqdGhpcykgKj0gYTt9CiAgYm9vbCBvcGVyYXRvcj09KGNvbnN0IG1pbnQmIGEpY29uc3R7IHJldHVybiB4ID09IGEueDt9Cn07Ci8vCgptYXA8dmksaW50PiBtcDsKdnZpIHBtOwp2dmkgdG87Cgp2b2lkIGdlbnN0KCkgewogIHZpIGEoNCk7CiAgcmVwKGksNCkgYVtpXSA9IGk7CiAgcXVldWU8dmk+IHE7CiAgbXBbYV0gPSAwOwogIHBtID0gdnZpKDE1KTsKICBwbVswXSA9IGE7CiAgdG8gPSB2dmkoMTUsdmkoMTw8NCkpOwogIHEucHVzaChhKTsKICB3aGlsZShzeihxKSkgewogICAgYSA9IHEuZnJvbnQoKTsgcS5wb3AoKTsKICAgIC8vIHByaXYoYSk7CiAgICBpbnQgdiA9IG1wW2FdOwogICAgcmVwKGksMTw8NCkgewogICAgICB2aSBiKDQpOwogICAgICByZXAoaiw0KSBiW2pdID0gajsKICAgICAgcmVwKGosNClyZXAoayxqKSBpZiAoKGk+PmomMSkgJiYgKGk+PmsmMSkpIHsKICAgICAgICBpbnQgeGogPSBhW2pdOwogICAgICAgIGludCB4ayA9IGFba107CiAgICAgICAgaWYgKHhqID4geGspIHN3YXAoeGoseGspOwogICAgICAgIC8vIGJbeGtdID0geGo7CiAgICAgICAgbWlucyhiW3hrXSx4aik7CiAgICAgIH0KICAgICAgdmkgYyA9IGE7CiAgICAgIHJlcChqLDQpIGNbal0gPSBiW2Nbal1dOwogICAgICByZXAoaiw0KSBiW2pdID0gLTE7CiAgICAgIGludCBjbnQgPSAwOwogICAgICByZXAoaiw0KSB7CiAgICAgICAgaWYgKGJbY1tqXV0gIT0gLTEpIGNvbnRpbnVlOwogICAgICAgIGJbY1tqXV0gPSBjbnQrKzsKICAgICAgfQogICAgICByZXAoaiw0KSBjW2pdID0gYltjW2pdXTsKICAgICAgaW50IHUgPSAwOwogICAgICBpZiAobXAuY291bnQoYykpIHsKICAgICAgICB1ID0gbXBbY107CiAgICAgIH0gZWxzZSB7CiAgICAgICAgdSA9IHN6KG1wKTsKICAgICAgICBtcFtjXSA9IHU7CiAgICAgICAgcG1bdV0gPSBjOwogICAgICAgIHEucHVzaChjKTsKICAgICAgfQogICAgICB0b1t2XVtpXSA9IHU7CiAgICB9CiAgfQp9CgptaW50IGRwWzExXVsxNV1bMTw8NF1bNV1bOTBdWzE8PDRdOwoKaW50IG1haW4oKSB7CiAgaW50IG47CiAgc2NhbmYoIiVkJWQiLCZuLCZtb2QpOwogIGdlbnN0KCk7CiAgLy8gY291dDw8c3oobXApPDxlbmRsOwogIGRwWzBdWzBdWzBdWzBdWzBdWzBdID0gMTsKICByZXAoaSwxMClyZXAoaiwxNSlyZXAoaywxPDw0KXJlcChsLDMpcmVwKGgsNzcpcmVwKHUsMTw8NCkgewogICAgbWludCB4ID0gZHBbaV1bal1ba11bbF1baF1bdV07CiAgICBpZiAoeC54ID09IDApIGNvbnRpbnVlOwogICAgaW50IG5pID0gaSsxOwogICAgcmVwKGYsMTw8NClyZXAoZywxPDw0KSB7CiAgICAgIGlmIChpID09IDAgJiYgZyAhPSBmKSBjb250aW51ZTsKICAgICAgaWYgKChnJmYpICE9IGcpIGNvbnRpbnVlOwogICAgICBtaW50IHAgPSAxOwogICAgICBpZiAoaSkgcmVwKHIsNCkgaWYoZz4+ciYxKSBwICo9IDI7CiAgICAgIGludCBuaiA9IHRvW2pdW2ZdOwogICAgICBpbnQgbmsgPSBrXmc7CiAgICAgIGludCBubCA9IGwrcGNudChnKSUyOwogICAgICBpbnQgbmggPSBoK3BjbnQoZikqMi1wY250KGcpOwogICAgICBpbnQgbnUgPSB1fGY7CiAgICAgIGRwW25pXVtual1bbmtdW25sXVtuaF1bbnVdICs9IHgqcDsKICAgICAgLy8gY291dDw8aTw8IiAiPDxqPDwiICI8PGs8PCIgIjw8bDw8IiAiPDxoPDwiICI8PHU8PCIgIjw8Zjw8IiAiPDxnPDxlbmRsOwogICAgICAvLyBjb3V0PDxuaTw8IiAiPDxuajw8IiAiPDxuazw8IiAiPDxubDw8IiAiPDxuaDw8IiAiPDxudTw8IiAiPDx4Lng8PCIgIjw8cC54PDxlbmRsOwogICAgfQogIH0KICBtaW50IGFucyA9IDA7CiAgcmVwKGosMTUpcmVwKGssMTw8NClyZXAobCwzKXJlcCh1LDE8PDQpIHsKICAgIGlmIChwY250KGspK2wgPiAyKSBjb250aW51ZTsKICAgIHZpIGEgPSBwbVtqXTsKICAgIHNldDxpbnQ+IHM7CiAgICByZXAoaSw0KSBpZiAodT4+aSYxKSBzLmluc2VydChhW2ldKTsKICAgIGlmIChzeihzKSA9PSAxKSBhbnMgKz0gZHBbMTBdW2pdW2tdW2xdW25dW3VdOwogIH0KICBjb3V0PDxhbnMueDw8ZW5kbDsKICByZXR1cm4gMDsKfQoKCgoKCg==