#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>

template <class Modulus>
class runtime_modular {
public:
  using value_type = uint32_t;
  using max_type = uint64_t;
  static value_type mod() { return Modulus::value; } 

  template <class T>
  static value_type normalize(T value_) {
    if (value_ < 0) {
      value_ = -value_;
      value_ %= mod();
      if (value_ == 0) return 0;
      return mod() - value_;
    }
    return value_ % mod();
  }

private:
  value_type value;

public:
  runtime_modular(): value(0) { }
  template <class T>
  explicit runtime_modular(T value_): value(normalize(value_)) { }
  template <class T>
  explicit operator T() { return static_cast<T>(value); }

  value_type operator () () const { return value; }
  runtime_modular operator - () const { return runtime_modular(mod() - value); }
  runtime_modular operator ~ () const { return inverse(); }

  value_type &extract() { return value; }
  runtime_modular inverse() const { return power(mod() - 2); }
  runtime_modular power(max_type exp) const {
    runtime_modular res(1), mult(*this);
    while (exp > 0) {
      if (exp & 1) res *= mult;
      mult *= mult;
      exp >>= 1;
    }
    return res;
  }

  runtime_modular operator + (const runtime_modular &rhs) const { return runtime_modular(*this) += rhs; }
  runtime_modular& operator += (const runtime_modular &rhs) { 
    if ((value += rhs.value) >= mod()) value -= mod(); 
    return *this; 
  }

  runtime_modular operator - (const runtime_modular &rhs) const { return runtime_modular(*this) -= rhs; }
  runtime_modular& operator -= (const runtime_modular &rhs) { 
    if ((value += mod() - rhs.value) >= mod()) value -= mod(); 
    return *this; 
  }

  runtime_modular operator * (const runtime_modular &rhs) const { return runtime_modular(*this) *= rhs; }
  runtime_modular& operator *= (const runtime_modular &rhs) { 
    value = (max_type) value * rhs.value % mod();
    return *this;
  }

  runtime_modular operator / (const runtime_modular &rhs) const { return runtime_modular(*this) /= rhs; }
  runtime_modular& operator /= (const runtime_modular &rhs) { return (*this) *= rhs.inverse(); }

  bool zero() const { return value == 0; }
  bool operator == (const runtime_modular &rhs) const { return value == rhs.value; }
  bool operator != (const runtime_modular &rhs) const { return value != rhs.value; }
  friend std::ostream& operator << (std::ostream &stream, const runtime_modular &rhs) {
    return stream << rhs.value;
  }

};

struct modulus_type { static uint32_t value; };
uint32_t modulus_type::value;
uint32_t &extracted_mod = modulus_type::value;
using modint = runtime_modular<modulus_type>;

int main() {
  int N;
  std::cin >> N >> extracted_mod;
  int N_ = 3 * N;
  std::vector<std::vector<modint>> doubles(N_ + 1, std::vector<modint>(N_ + 1));
  std::vector<std::vector<modint>> triples(N_ + 1, std::vector<modint>(N_ + 1));
  doubles[0][0] = triples[0][0] = modint(1);
  for (int i = 0; i < N_; ++i) {
    for (int j = 0; j <= i; ++j) {
      doubles[i + 1][j] += doubles[i][j];
      if (j + 1 <= i) {
        doubles[i + 1][j + 2] += doubles[i][j] * modint(i - j);
      }
      triples[i + 1][j] += triples[i][j];
      if (j + 2 <= i) {
        triples[i + 1][j + 3] += triples[i][j] * modint(i - j) * modint(i - j - 1);
      }
    }
  }
  for (int i = 0; i <= N_; ++i) {
    for (int j = 0; j < N_; ++j) {
      triples[i][j + 1] += triples[i][j];
    }
  }
  modint ans;
  for (int i = 0; i <= N; ++i) {
    ans += doubles[N_][2 * i] * triples[N_ - 2 * i][N_ - 3 * i];
  }
  std::cout << ans << '\n';
}


Measured memory_bytes: 281984