import java.util.Scanner

fun main(args: Array<String>){
    val scanner = Scanner(System.`in`)
    val result = D1015B(
                    numberOfBall  = scanner.nextInt()
                   ,numberOfPaint = scanner.nextInt()
                 ).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()
    }
}