#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__);fflush(stderr);
#else
	#define eprintf(...) 42
#endif

using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
template<typename T>
using pair2 = pair<T, T>;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
	return (ull)rng() % B;
}

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second

clock_t startTime;
double getCurrentTime() {
	return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}


const ll MOD = 998244353;
ll add(ll x, ll y) {
	x += y;
	if (x >= MOD) return x - MOD;
	return x;
}
ll sub(ll x, ll y) {
	x -= y;
	if (x < 0) return x + MOD;
	return x;
}
ll mult(ll x, ll y) {
	return (x * y) % MOD;
}
ll bin_pow(ll x, ll p) {
	if (p == 0) return 1;
	if (p & 1) return mult(x, bin_pow(x, p - 1));
	return bin_pow(mult(x, x), p / 2);
}
ll rev(ll x) {
	return bin_pow(x, MOD - 2);
}


const int N = 5050;
int n, m;
int pw[N][N];

int main()
{
	startTime = clock();
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	for (int x = 0; x < N; x++) {
		pw[x][0] = 1;
		for (int i = 1; i < N; i++)
			pw[x][i] = mult(pw[x][i - 1], x);
	}
	scanf("%d%d", &n, &m);
	int ans = 0;
	for (int i = 0; i < n; i++)
		for (int x = 1; x <= m; x++) {
			ans = add(ans, mult(pw[m - x][i], pw[m][n - 1 - i]));
		}
	for (int d = 1; d < n; d++)
		for (int x = 1; x <= m; x++) {
			ans = add(ans, mult(mult(n - d, x - 1), mult(pw[m - x][d - 1], pw[m][n - 1 - d])));
		}
	printf("%d\n", ans);

	return 0;
}

// Problem: C - Sequence Scores
// Contest: AtCoder - AtCoder Regular Contest 114
// URL: https://atcoder.jp/contests/arc114/tasks/arc114_c
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

//愿神 zhoukangyang 指引我。
#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read(){
	int s=0,w=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
	return s*w;
}
const int p=998244353;
int Q[5003][5003];
int qp(int x,int y)
{
	return Q[x][y];
}
signed main()
{
	for(int i=1; i<=5000; i++)
	{
		Q[i][0]=1;
		for(int j=1; j<=5000; j++) Q[i][j]=Q[i][j-1]*i%p;
	}
	int n=read(),m=read(),ans=0;
	for(int i=1; i<=n-2; i++) for(int j=1; j<=m; j++) 
		ans+=(j-1)*(j-1)*(n-i-1)%p*(p+qp(m-j+1,i)-qp(m-j,i))%p*qp(m,n-i-2)%p,ans%=p;
	for(int r=1; r<=n; r++) for(int i=1; i<=m; i++)
	{
		int t=1,k=n-r;
		if(r^n) t=1ll*t*(i-1)%p,k--;
		ans+=1ll*t*(p+qp(m-i+1,r)-qp(m-i,r))%p*qp(m,k)%p,
		ans%=p;
	}
	for(int l=2;l<=n;l++) for(int i=1;i<=m;i++)
	{
		ans+=1ll*(i-1)*(p+qp(m-i+1,n-l+1)-qp(m-i,n-l+1))%p*qp(m,l-2)%p,
		ans%=p;
	}
	printf("%lld\n",ans);
    return 0;
}