#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B;
string S;
const ll MOD = 998244353;
//const ll MOD = (1e+9) + 7;
const ll INF = 1LL<<60;
typedef pair<ll, ll> P;

class mint{
    public:
        ll x;
        unsigned long long mod;
        mint(){}
        constexpr mint(unsigned long long mod): x(0), mod(mod){}
        constexpr mint(ll x, unsigned long long mod) : x((x % mod + mod)%mod), mod(mod) {}
        constexpr mint& operator=(const ll &a){
            x = a;
            return *this;
        }

        constexpr mint operator-(){
            return mint(x == 0 ? 0 : mod - x, mod);
        }
        constexpr mint& operator+=(const mint& a){
            if((x += a.x) >= mod) x -= mod;
            return *this;
        }
        constexpr mint operator+(const mint& a) const{
            mint res(*this);
            return res += a;
        }
        constexpr mint& operator-=(const mint& a){
            if((x -= a.x) < 0) x += mod;
            return *this;
        }
        constexpr mint operator-(const mint& a) const{
            mint res(*this);
            return res -= a;
        }
        constexpr mint& operator*=(const mint& a){
            (x *= a.x)%=mod;
            return *this;
        }
        constexpr mint& operator*=(const ll& a){
            mint temp(a, mod);
            return *this *= temp;
        }
        constexpr mint operator*(const mint& a) const{
            mint res(*this);
            return res *= a;
        }
        constexpr mint operator*(const ll& a) const{
            mint res(*this);
            return res *= a;
        }
        constexpr mint pow(unsigned long long pw) const{
            mint res(1, mod), comp(*this);
            while(pw){
                if(pw&1) res *= comp;
                comp *= comp;
                pw >>= 1;
            }
            return res;
        }
        //以下、modが素数のときのみ
        constexpr mint inv() const{
            mint res(*this);
            return res.pow(mod - 2);
        }
        constexpr mint& operator/=(const mint &a){
            (x *= a.inv().x)%=mod;
            return *this;
        }
        constexpr mint operator/(const mint &a) const{
            mint res(*this);
            return res /= a;
        }
};
ostream& operator<<(ostream& os, const mint& a){
    os << a.x;
    return os;
}

int main() {
    cin>>N>>M;
    vector<vector<mint> >  dp(N + 1, vector<mint>(N * 3 + 1, mint(0, M)));
    dp[N][N * 3] = 1;
    mint ans(0, M);
    Rrep(i, N + 1){
        Rrep(j, N * 3 + 1){
            if(i == 0){
                ans += dp[i][j];
            }else{
                if(j >= 1) dp[min(i, (j - 1) / 2)][j - 1] += dp[i][j];
                if(j >= 2) dp[i - 1][j - 2] += dp[i][j] * (j - 1);
                if(j >= 3) dp[min(i - 1, (j - 3) / 2)][j - 3] += dp[i][j] * (j - 1) * (j - 2);
            }
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 188032