'use strict'

function main(s) {
  	let orders = s.split(' ').map(n => Number(n));
  	let N = orders[0],K = orders[1];
  	let ans = K *  Math.pow(K - 1, N - 1);
    console.log(ans);
}

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