import scala.math.pow

object Main {
  def main(args: Array[String]): Unit = {
    val List(n, k) = io.StdIn.readLine.split(' ').toList.map(c => c.toInt)
    val answer = k * pow((k - 1), (n - 1)).toLong

    println(answer)
  }
}
