fun main(args: Array<String>) {
    val (N, K) = readLine()!!.split(" ").map(String::toInt)

    if (N == 1) {
        println(K)
        return
    }

    (2..N).fold(K.toLong()) { acc, elm ->
        acc * (K - 1)
    }.let(::println)

}

