## https://yukicoder.me/problems/no/1552 MOD = 998244353 def my_pow(a, x, pow_cache): if (a, x) in pow_cache: return pow_cache[(a, x)] if a == 0: pow_cache[(a, x)] = 0 return 0 else: pow_cache[(a, x)] = pow(a, x, MOD) return pow_cache[(a, x)] def linear_sum(N, pow_cache): ans = (N * (N + 1)) % MOD ans *= my_pow(2, MOD - 2, pow_cache) ans %= MOD return ans def main(): N, M = map(int, input().split()) # 最小値から考える answer_min = 0 pow_cache = {} max_linear_sum = linear_sum(M, pow_cache) for m in range(1, M + 1): min_linear_sum = linear_sum(m - 1, pow_cache) diff_linear_sum = (max_linear_sum - min_linear_sum) % MOD m0 = M - m + 1 m0 = my_pow(m0, N - 1, pow_cache) m0 *= N m0 %= MOD a = (diff_linear_sum * m0) % MOD min_linear_sum2 = linear_sum(m, pow_cache) diff_linear_sum2 = (max_linear_sum - min_linear_sum2) % MOD b = my_pow(diff_linear_sum2, N, pow_cache) m0 = M - m m0 = my_pow(m0, N - 1, pow_cache) m0 *= N m0 %= MOD b = (diff_linear_sum2 * m0) % MOD c = (a - b) % MOD ans = (c * m) % MOD answer_min += ans answer_min %= MOD # 最大値 answer_max = 0 for m in range(1, M + 1): max_linear_sum = linear_sum(m, pow_cache) m0 = m m0 = my_pow(m0, N - 1, pow_cache) m0 *= N m0 %= MOD a = (max_linear_sum * m0) % MOD max_linear_sum2 = linear_sum(m - 1, pow_cache) m0 = m - 1 m0 = my_pow(m0, N - 1, pow_cache) m0 *= N m0 %= MOD b = (max_linear_sum2 * m0) % MOD c = (a - b) % MOD ans = (c * m) % MOD answer_max += ans answer_max %= MOD answer = (answer_max - answer_min) % MOD print(answer) if __name__ == "__main__": main()