'use strict'

function main(s) {

  s = s.split('\n')[0].split(' ').map(n => Number(n));
  const N = s[0];
  const K = s[1];

  let num = K;

  for (let i = 0; i < N - 1; i++) {
    num = num * (K - 1);
  }

  console.log(num);
}

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