var P = 2

fun mod(x: Int) = if (x >= 0) x % P else (P - ((-x) % P)) % P
fun modPlus(x1: Int, x2: Int) = (x1 + x2) % P
fun modMinus(x1: Int, x2: Int) = (x1 + P - x2) % P
fun modTimes(x1: Int, x2: Int): Int = ((x1.toLong() * x2.toLong()) % P).toInt()

class IntArray2D(val size1: Int, val size2: Int) {
  private val innerArray = IntArray(size1 * size2)

  operator fun get(i1: Int, i2: Int): Int = innerArray[i2 + size2 * i1]

  operator fun set(i1: Int, i2: Int, v: Int) {
    innerArray[i2 + size2 * i1] = v
  }
}

fun main(args: Array<String>) {
  val (n, p) = readLine()!!.split(" ").map { it.toInt() }
  P = p

  val pTable = IntArray(n + 1, { 0 })
  pTable[0] = 2
  for (i in 1..n) {
    pTable[i] = modTimes(pTable[i - 1], pTable[i - 1])
  }

  val cTable = IntArray2D(n + 1, n + 1)
  cTable[0, 0] = 1
  for (i in 1..n) {
    for (j in 0..i) {
      cTable[i, j] = if (j == 0) 1 else modPlus(cTable[i - 1, j - 1], cTable[i - 1, j])
    }
  }

  val gTable = IntArray2D(n + 1, n + 1)
  gTable[0, 0] = 1
  for (i in 1..n) {
    for (j in 0..i) {
      gTable[i, j] =
          if (j == 0 || j == i) 1
          else modPlus(gTable[i - 1, j - 1], modTimes(gTable[i - 1, j], j + 1))
    }
  }

  val hTable = IntArray2D(n + 1, n + 1)
  for (i in 0..n) {
    for (j in 0..n) {
      hTable[i, j] =
          if (i == 0 || j == 0) 1
          else if (i == 1) modTimes(hTable[1, j - 1], 2)
          else modTimes(hTable[i - 1, j], hTable[1, j])
    }
  }


  val fTable = IntArray(n + 1, { 0 })
  for (i in 1..n) {
    var acc = 0
    for (x in 0..i) {
      acc = modPlus(acc, modTimes(gTable[i, x], hTable[x, n - i]))
    }
    fTable[i] = modTimes(pTable[n - i], acc)
  }

  var ans = pTable[n]
  for (k in 1..n) {
    val sign = if (k % 2 == 0) 1 else mod(-1)
    ans = modPlus(ans, modTimes(modTimes(sign, cTable[n, k]), fTable[k]))
  }

  println(ans)
}