import io.{StdIn => in}
import scala.collection.mutable.HashSet

object Main extends App {
  val Array(n, k) = in.readLine.split(" ").map(_.toLong)
  val ans = k * (2L to n)./:(1L)((acc,_) => acc * (k-1))
  println(ans)
}