# mod バージョン N, K = map(int, input().split()) mod = 998244353 K_inv = pow(K, mod-2, mod) prob = 1 for i in range(N-2): prob *= K_inv prob %= mod prob *= (K-1) prob %= mod prob *= K_inv prob %= mod prob *= N prob %= mod print(prob)