import std.algorithm,
       std.string,
       std.array,
       std.range,
       std.stdio,
       std.conv;

void main() {
  ulong[] NK = readln.chomp.split.to!(ulong[]);
  ulong N = NK[0],
        K = NK[1];
  
  writeln(K * (K-1)^^(N-1));
}
