import java.lang.Math.*
import java.util.*

fun solvePaintingBallsWithAtcodeer(){
    val sc = Scanner(System.`in`)
    val node = sc.nextInt()
    val k = sc.nextInt()
    val ans = pow((k-1).toDouble(),(node-1).toDouble()).toInt() * k

    println(ans)
}

fun main(args: Array<String>){
    solvePaintingBallsWithAtcodeer()
}