  fun main(args: Array<String>) {
    val (N,K) = readLine()!!.split(" ").map{ i -> i.toInt() }
    var result = 1
    for(i in 1..N){
      if(i == 1) {
        result *= K
        continue
        }
      result *= K-1
    }
    println(result)
}