'use strict'

function main(s) {

  s = s.split('\n')[0].split(' ').map(x => Number(x));
  const N = s[0];
  const K = s[1];
  const result = K * Math.pow(K - 1, N - 1);

  console.log(result);

}

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