#include <bits/stdc++.h>
using namespace std;

const int N = 5005, mod = 998244353;

int n, m, ans, f[N][N];

int fpow_(int a, int b, int res = 1) {
	for (; b; b >>= 1, a = 1ll*a*a%mod)
		if (b&1)
			res = 1ll*res*a%mod;
	return res;
}

int main() {
	scanf("%d%d", &n, &m);
	ans = 1ll*fpow_(m, n)*n%mod;
	f[0][0] = 1;
	for (int k = 1; k <= m; k++) {
		f[k][0] = 1;
		for (int i = 1; i <= n; i++)	
			f[k][i] = 1ll*f[k][i - 1]*k%mod;
	}
	for (int i = 2; i <= n; i++)
		for (int j = 1; j <= m; j++)
			ans = (ans - 1ll*f[m][n - i]*(n - i + 1)%mod*f[m - j][i - 2])%mod;
	printf("%d\n", (ans%mod + mod)%mod);
}
#include<bits/stdc++.h>
using namespace std;
struct fast_ios { fast_ios(){ cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(20); }; } fast_ios_;
#define Local
#ifdef Local
  #define dbg(args...) do { cout << #args << " -> "; err(args); } while (0)
  void err() { std::cout << std::endl; }
  template<typename T, typename...Args>
  void err(T a, Args...args) { std::cout << a << ' '; err(args...); }
  template <template<typename...> class T, typename t, typename... A> 
  void err(const T <t> &arg, const A&... args) {
  for (auto &v : arg) std::cout << v << ' '; err(args...); }
#else
  #define dbg(...)
#endif
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pint;
typedef pair<ll,ll> plint;
const int mod = 998244353;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

const int N = 2e5 + 10; 
template<int mod>
struct ModInt{
	int x;
	ModInt () : x(0) {}
	ModInt (int64_t x) : x(x >= 0 ? x % mod : (mod - -x % mod) % mod) {}
	ModInt &operator += (const ModInt &p){
		if ((x += p.x) >= mod) x -= mod;
		return *this;
	}
	ModInt &operator -= (const ModInt &p) {
		if ((x += mod - p.x) >= mod) x -= mod;
		return *this;
	}
	ModInt &operator *= (const ModInt &p) {
		x = (int64_t) x * p.x % mod;
		return *this;
	}
	ModInt &operator /= (const ModInt &p) {
		*this *= p.inverse();
		return *this;
	}
	ModInt &operator ^= (int64_t p) {
		ModInt res = 1;
		for (; p; p >>= 1) {
			if (p & 1) res *= *this;
			*this *= *this;
		}
		return *this = res;
	}
	ModInt operator - () const { return ModInt(-x); }
	ModInt operator + (const ModInt &p) const { return ModInt(*this) += p; }
	ModInt operator - (const ModInt &p) const { return ModInt(*this) -= p; }
	ModInt operator * (const ModInt &p) const { return ModInt(*this) *= p; }
	ModInt operator / (const ModInt &p) const { return ModInt(*this) /= p; }
	ModInt operator ^ (int64_t p) const { return ModInt(*this) ^= p; }
	bool operator == (const ModInt &p) const { return x == p.x; }
	bool operator != (const ModInt &p) const { return x != p.x; }
	explicit operator int() const { return x; }
	ModInt &operator = (const int p) { x = p; return *this;}
	ModInt inverse() const {
		int a = x, b = mod, u = 1, v = 0, t;
		while (b > 0) {
			t = a / b;
			a -= t * b;
			std::swap(a, b);
			u -= t * v;
			std::swap(u, v);
		}
		return ModInt(u);
	}
	friend std::ostream & operator << (std::ostream &stream, const ModInt<mod> &p) {
		return stream << p.x;
	}
	friend std::istream & operator >> (std::istream &stream, ModInt<mod> &a) {
		int64_t x;
		stream >> x;
		a = ModInt<mod>(x);
		return stream;
	}
};
typedef ModInt<998244353> mint;


int main()
{
	int n, m;
	cin >> n >> m;
	vector<mint> pw(n + 1, 1);
	for (int i = 1; i <= n; ++i) pw[i] = pw[i - 1] * mint(m);
	//vector<mint> sum(m + 1, 1);
	vector< vector<mint> > pws(m + 1, vector<mint> (n + 1, 1));
	for (int i = 1; i <= m; ++i) {
		for (int j = 1; j <= n; ++j) {
			pws[i][j] = pws[i][j - 1] * mint(m - i);
		}
	}
	// pws[i][j] = (m - i) ^ j;
	vector< vector<mint> > sum(n + 1, vector<mint> (m + 1 , 0));
	// (m - x) ^ (k)  x : 1 -> m
	// sum[i][j] = 
	for (int i = 0; i <= n; ++i) {
		for (int j = 1; j <= m; ++j) {
			sum[i][j] = sum[i][j - 1] + pws[j][i];
		}
	}
	mint ans = 0;

	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j < i; ++j) {
			ans += sum[i - j - 1][m] * pw[n - 1 - (i - j)];
		}
	}
	
	cout << mint(n) * pw[n] - ans << endl;
    return 0;
}