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

void main() {
  auto NK = readln.chomp.split.map!(to!int);
  auto N = NK[0];
  auto K = NK[1];

  (K * pow(K - 1, N - 1)).writeln;
}
