'use strict'

function main(input) {
  const inputList = input.split(' ');
  const n = Number(inputList[0])
  const k = Number(inputList[1])
  
  let pattern = k
  for (let i=1; i<n; i++) {
    pattern = pattern * (k-1)
  }
  console.log(pattern)
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));