///A drunk man will find his way home, but a drunk bird may get lost forever...
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
using namespace std;
//template <typename T>
//using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef tree<double, null_type, less_equal<double>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define int long long
typedef long long ll;
typedef double dd;
typedef long double ldd;
typedef pair <int, int> pii;
typedef pair <pii , int> ppii;
#define pb push_back
#define pf push_front
#define ppb pop_back()
#define ppf pop_front()
#define f first
#define s second
#define sz(x) (int)x.size()
#define smin(x , y) x = min(x , y)
#define smax(x , y) x = max(x , y)
#define mp make_pair
#define all(x) x.begin() , x.end()
#define debug(x) cerr<< #x << " = " << x << endl
#define ddebug(x, y) cerr<< #x << " = " << x  << ", " << #y << " = " << y << endl
#define uop(x, y) pii(min(x, y), max(x, y))
#define out return cout << "No" << endl, 0
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")
const int mx = 6e3 + 10;
int n, m, fact[mx], inv[mx], C[mx][mx], M2[mx], M3[mx], p[mx];
int _pow(int a, int b){
	if(!b)
		return 1;
	return ((_pow((a * a) % m, b >> 1) * ((b & 1) ? a : 1)) % m);
}
void pre(){
	fact[0] = 1;
	for(int i = 1; i <= 3 * n; i++)
		fact[i] = (fact[i - 1] * i) % m;
	inv[3 * n] = _pow(fact[3 * n] , m - 2);
	for(int i = 3 * n - 1; ~i; i--)
		inv[i] = (inv[i + 1] * (i + 1)) % m;
	for(int i = 0; i <= 3 * n; i++)
		for(int j = 0; j <= i; j++)
			C[i][j] = fact[i] * inv[j] % m * inv[i - j] % m;
	M2[0] = 1;
	for(int i = 2; i <= 3 * n; i += 2)
		M2[i] = M2[i - 2] * C[i][2] % m;
	M3[0] = 1;
	for(int i = 3; i <= 3 * n; i += 3)
		M3[i] = M3[i - 3] * C[i][3] % m;
	p[0] = 1;
	for(int i = 1; i <= 3 * n; i++)
		p[i] = p[i - 1] * 2 % m;
	return;
}
int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> n >> m;
	pre();
	int ans = 0;
	for(int a = 0; a <= n; a++)
		for(int b = 0; b <= n; b++){
			int c = 3 * n - 3 * a - 2 * b;
			if(c < b)
				continue;
			int cnt = (C[3 * n][3 * a] * p[a] % m * M3[3 * a] % m * inv[a] % m) % m;
			cnt = cnt * (C[3 * n - 3 * a][2 * b] * M2[2 * b] % m * inv[b] % m) % m;
			ans = (ans + cnt) % m;
		}
	cout << ans << endl;
	return 0;
} 

#define _CRT_SECURE_NO_WARNINGS
#define _SCL_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <utility>
#include <algorithm>
#include <functional>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <limits>
#include <numeric>
#include <valarray>
#include <fstream>
#include <array>
#include <random>
#include <unordered_set>
#include <unordered_map>

using namespace std;
using uint = uint32_t;
using LL = int64_t;
using ULL = uint64_t;
using PP = pair<LL, LL>;
template <typename T> using PriorityQ = priority_queue<T, vector<T>, greater<T> >;
#define REP(i, a, n) for(LL i = (a), i##_max_ = (n); i < i##_max_; ++i)
#define REM(i, a, n) for(LL i = (LL)(n) - 1, i##_min_ = (a); i >= i##_min_; --i)
#define FLOAT fixed << setprecision(16)
#define SPEEDUP { cin.tie(NULL); ios::sync_with_stdio(false); }
const int INF = 0x3FFFFFFF;
const LL INFLL = 0x3FFFFFFF3FFFFFFF;
const double INFD = 1.0e+308;
const double EPS = 1.0e-9;

void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
template <class T, class U> istream& operator>>(istream& ist, pair<T, U>& right) { return ist >> right.first >> right.second; }
template <class T, class U> ostream& operator<<(ostream& ost, const pair<T, U>& right) { return ost << right.first << ' ' << right.second; }
template <class T, class TCompatible, size_t N> void Fill(T(&dest)[N], const TCompatible& val) { fill(dest, dest + N, val); }
template <class T, class TCompatible, size_t M, size_t N> void Fill(T(&dest)[M][N], const TCompatible& val) { for (int i = 0; i < M; ++i) Fill(dest[i], val); }
template <class T> T Next() { T buf; cin >> buf; return buf; }
istream& Ignore(istream& ist) { string s; ist >> s; return ist; }
bool Inside(int i, int j, int h, int w) { return i >= 0 && i < h && j >= 0 && j < w; }

#ifdef ONLY_MY_ENVIR
#include "Accumulator.h"
#include "Algebraic.h"
#include "BinaryMatrix.h"
#include "BinaryTree.h"
#include "Bipartite.h"
#include "BIT.h"
#include "Compressor.h"
#include "Decompositions.h"
#include "DynamicMod.h"
#include "Factorization.h"
#include "FFT.h"
#include "FlowSolver.h"
#include "Graph.h"
#include "GraphUtil.h"
#include "IntMod.h"
#include "LazySegmentTree.h"
#include "LIS.h"
#include "Math.h"
#include "MathUtil.h"
#include "Matrix.h"
#include "MinCostFlowSolver.h"
#include "MinMax.h"
#include "Numbers.h"
#include "Optimize.h"
#include "Permutation.h"
#include "Polynomial.h"
#include "Position.h"
#include "Range.h"
#include "Rational.h"
#include "SegmentTree.h"
#include "SegmentTree2D.h"
#include "Sets.h"
#include "Shortest.h"
#include "SlidingWindow.h"
#include "SpanningTree.h"
#include "StringSearching.h"
#include "SuffixArray.h"
#include "Tree.h"
#include "TreeUtil.h"
#include "UnionFind.h"
#include "Util.h"
#include "VectorUtil.h"
#endif

#ifdef __GNUC__
typedef __int128 LLL;
istream& operator>>(istream& ist, __int128& val) { LL tmp; ist >> tmp; val = tmp; return ist; }
ostream& operator<<(ostream& ost, __int128 val) { LL tmp = val; ost << tmp; return ost; }
#endif

int N, MOD;
LL DP[6001][9001];

void add(LL& a, LL b) {
	a += b;
	if (a >= MOD) {
		a -= MOD;
	}
}

int main() {
	cin >> N >> MOD;
	N *= 3;

	const int Q = N / 2;

	DP[0][Q] = 1;
	REP(i, 0, N) {
		REP(k, -(i / 2), i + 1) {
			if (i + 1 <= N) add(DP[i + 1][Q + k + 1], DP[i][Q + k]);
			if (i + 2 <= N) add(DP[i + 2][Q + k - 1], DP[i][Q + k] * (i + 1) % MOD);
			if (i + 3 <= N) add(DP[i + 3][Q + k + 0], DP[i][Q + k] * (i + 1) % MOD * (i + 2) % MOD);
		}
	}

	LL sum = 0;
	REP(k, 0, N + 1) {
		add(sum, DP[N][Q + k]);
	}
	cout << sum << endl;
	return 0;
}

