process.stdin.resume();
process.stdin.setEncoding('utf8');

process.stdin.on('data', function (chunk) {
    var lines = chunk.toString().split(' ');
    var place = parseInt(lines[0]);
    var color = parseInt(lines[1]);
    
    var ans = color * Math.pow((color - 1),place - 1)
        console.log(ans);
});