#include using i64 = long long; constexpr i64 P = 998244353; i64 norm(i64 a) { a %= P; if (a < 0) a += P; return a; } i64 modpow(i64 a, i64 e) { i64 r = 1; a = norm(a); while (e > 0) { if (e & 1) r = r * a % P; a = a * a % P; e >>= 1; } return r; } i64 quotient(i64 a, i64 b) { return norm(a) * modpow(b, P - 2) % P; } int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); i64 N, M; std::cin >> N >> M; i64 ans = 0, power = 1, m = norm(M); for (i64 i = 1; i < N; ++i) { power = power * m % P; ans = norm(ans + (((N - 1 - i) & 1) ? -power : power)); } std::cout << ans << '\n'; return 0; }