n, k = list(map(int, input().split()))

print((k * (k - 1) ** max(0, n - 1)))

n, k = list(map(int, input().split()))

print((k * (k - 1) ** (n - 1)))

n, k = list(map(int, input().split()))
print((k * (k - 1) ** max(0, n - 1)))

n, k = list(map(int, input().split()))
print((k * (k - 1) ** (n - 1)))

-print((k * (k - 1) ** max(0, n - 1))) +print((k * (k - 1) ** (n - 1)))