import java.util.Scanner

object Main extends App {
  val sc = new Scanner(System.in)
  val Vector(n, k) = Vector.fill(2)(sc.nextInt)

  val ans = k * pow(k - 1, n - 1)

  def pow(x: Int, y: Int): Int = {
    Range(0, y).fold(1)((acc, _) => acc * x)
  }

  println(ans)
}
