object Main extends App {

  /**
    *
    * @param n num of balls
    * @param k num of colours
    * @return
    */
  def solve(n: Int, k: Int): Int = {
    k * math.pow(k - 1, n - 1).toInt
  }

  val scanner = new java.util.Scanner(Console.in)
  val n = scanner.nextInt()
  val k = scanner.nextInt()
  val ans = solve(n, k)
  println(ans)
}