object Main {
  def main(args: Array[String]): Unit = {
    import scala.io.StdIn.readLine
    val Array(datN, datK) = readLine.split(" ").map(_.toInt)

    val ans = datK * math.pow((datK - 1), (datN - 1))
    println(ans.toInt)
  }
}
