"use strict";

var main = function main(input) {
  var args = input.split(' ');
  var N = args[0];
  var K = args[1];
  console.log(K * Math.pow(K - 1, N - 1));
};

main(require('fs').readFileSync('/dev/stdin', 'utf-8'));