object Main extends App {
  val input = io.Source.stdin.getLines.toSeq.head.split(' ').map(_.toInt)
  val N=input(0)
  val K=input(1)
  var i=1
  var ret=K
  while(i<N){
    ret = (ret * (K-1))
    i += 1
  } 
  println(ret)
}
