import java.util.*

fun main(omkar: Array<String>) {
    val jin = Scanner(System.`in`)
    val n = jin.nextInt()
    val m = jin.nextLong()
    val choice2 = LongArray(n + 1)
    choice2[0] = 1L
    for (j in 1..n) {
        choice2[j] = (((2 * j) - 1).toLong() * choice2[j - 1]) % m
    }
    val choice3 = LongArray(n + 1)
    choice3[0] = 1L
    for (j in 1..n) {
        choice3[j] = ((((3 * j) - 1) * ((3 * j) - 2)).toLong() * choice3[j - 1]) % m
    }
    val choose = Array((3 * n) + 1) { LongArray(it + 1) }
    choose[0][0] = 1L
    for (j in 1..3 * n) {
        choose[j][0] = 1L
        choose[j][j] = 1L
        for (k in 1 until j) {
            choose[j][k] = (choose[j - 1][k] + choose[j - 1][k - 1]) % m
        }
    }
    var answer = 0L
    for (b in 0..n) {
        for (c in 0..n - b) {
            var addend = choose[3 * n][2 * b] * choose[(3 * n) - (2 * b)][3 * c]
            addend %= m
            addend *= choice2[b]
            addend %= m
            addend *= choice3[c]
            addend %= m
            answer += addend
            answer %= m
        }
    }
    println(answer)
}