function Main(inp) {
    var input = inp.split('\n')[0].split(' ').map(function(n) {
        return Number(n);
    });
    var number = input[0];
    var colors = input[1];
    var patterns = colors * Math.pow(colors - 1, number - 1); 
    console.log(patterns);
}

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