import scala.io.Source
import math.pow
object Main {
  def main(args: Array[String]) {
    val s = Source.stdin.getLines.toSeq.head.split(" ")
    val (n, k) = (s(0).toInt, s(1).toInt)
    println(k * pow(k-1, n-1).toInt)
  }
}
