using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static long NN => long.Parse(ReadLine()); static long[] NList => ReadLine().Split().Select(long.Parse).ToArray(); public static void Main() { Solve(); } static void Solve() { var c = NList; var (n, m) = (c[0], c[1]); WriteLine(Dice(n, m)); } static long Dice(long n, long m) { checked{ var ans = 0L; var mod = 998_244_353; var rev2 = 499_122_177; var nc = n % mod; var revn = Exp(nc, mod - 2, mod); for (var i = 1; i < m; ++i) { if (i == 1) { var tb = (Exp(i + 1, n - 1, mod) - Exp(i, n - 1, mod) + mod) % mod * nc % mod; var count = tb * 2 % mod; var add = (tb * (i + 2) % mod * (m - i) % mod + count % mod * (m - 2) % mod * (m - 1) % mod * rev2 % mod) * i % mod; ans = (ans + add) % mod; } else { var tb = (Exp(i + 1, n - 1, mod) - Exp(i, n - 1, mod) + mod) % mod * nc % mod; var mid = (Exp(i + 1, n - 1, mod) - Exp(i, n - 1, mod) * 2 + Exp(i - 1, n - 1, mod) + mod + mod) % mod * nc % mod; var count = (tb * 2 + mid * (i - 1) % mod) % mod; var add = ((tb * (i + 2) % mod + (i * (i + 1L) % mod * rev2 % mod - 1 + mod) % mod * mid % mod) % mod * (m - i) % mod + count % mod * (m - i - 1) % mod * (m - i) % mod * rev2 % mod) * i % mod; ans = (ans + add) % mod; } } return ans; } } static long Exp(long n, long p, int mod) { long _n = n % mod; var _p = p; var result = 1L; if ((_p & 1) == 1) result *= _n; while (_p > 0) { _n = _n * _n % mod; _p >>= 1; if ((_p & 1) == 1) result = result * _n % mod; } return result; } }