N, K = list(map(int, input().split()))

A = K

if N != 1:

    for i in range(N - 1):

        A *= (K - 1)

print(A)
N, K = list(map(int, input().split()))

print((K * (K - 1) ** (N - 1)))
N, K = list(map(int, input().split()))
A = K
if N != 1:
    for i in range(N - 1):
        A *= K - 1
print(A)

N, K = list(map(int, input().split()))
print((K * (K - 1) ** (N - 1)))

-A = K -if N != 1: -    for i in range(N - 1): -        A *= K - 1 -print(A) +print((K * (K - 1) ** (N - 1)))