
 fun main(args: Array<String>){
    val input = readLine()!!.split(' ')
                            .map  { it.toInt() }
                            .toTypedArray()
    val result = D1015B(
                    numberOfBall  = input[0]
                   ,numberOfPaint = input[1]
                 ).judge()
    println(result)
}
 
class D1015B(
  val numberOfBall:  Int
 ,val numberOfPaint: Int
){
    fun judge(): Int{
        return numberOfPaint * 
               Math.pow(numberOfPaint - 1.toDouble(), numberOfBall-1.toDouble())
                   .toInt()
    }
}