import java.util.Scanner

object Main {
  def main(args: Array[String]) {
    if (args.length > 0 && args(0) == "TEST") {
      println(test())
    } else {
      val input = io.Source.stdin.getLines().mkString("\n")
      println(solve(input).trim())
    }
  }

  def mpow(b: Long, e: Long): Long = {
    def doMpow(r: Long, b: Long, e: Long): Long = {
      if (e == 0) r
      else {
        val r1 = if ((e & 1) == 1) r * b else r
        doMpow(r1, b * b, e >> 1)
      }
    }
    doMpow(1, b, e)
  }

  def solve(input: String): String = {
    val s: Scanner = new Scanner(input)
    val n, k = s.nextLong
    (k * mpow(k - 1, n - 1)).toString
  }

  val tests = List(
    "2 2" -> "2",
    "1 10" -> "10",
    "10 8" -> "322828856"
  )

  def test(): String = tests.map { case (i, o) => (i.trim(), o.trim()) }
    .zipWithIndex.map {
    case ((input, outputExpect), i) =>
      val output = solve(input).trim()
      val tnum = i + 1
      s"test$tnum:" + (
        if (output == outputExpect) "Passed"
        else s"Failed\nexpect:\n$outputExpect\noutput:\n$output")
  }
    .mkString("\n")
}