#include <stdio.h>
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define puu pair<ull,ull>
#define fi first
#define se second
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define mset(a, b) memset(a, b, sizeof a)
 
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

const int N = 5010;
 
const int P = 998244353;
 
inline int mul(int x, int y) {return 1ll * x * y % P;}
inline int add(int x, int y) {return x + y >= P ? x + y - P : x + y;}
inline void upd(int &x, int y) {x = add(x, y);};
 
int n, m;
int f[N][N], s[N][N], h[N][N], p[N][N];
 
int main() {
	cin >> n >> m;
	for (int i = 1; i <= n; i++) f[i][m] = 1;
	for (int i = 0; i <= m; i++)
		for (int j = 0; j <= n; j++) {
			if (j == 0) {p[i][j] = 1; continue;}
			if (i == 0) {p[i][j] = 0; continue;} 
			p[i][j] = mul(p[i][j - 1], i);
		}
	for (int j = m - 1; j >= 1; j--) {
		for (int i = 1; i <= n; i++) {
			upd(h[i + 1][j], f[i][j + 1]);
			upd(h[i][j], mul(h[i - 1][j], (m - j + 1)));
		}
		for (int i = 1; i <= n; i++) {
			upd(s[i][j], mul(s[i - 1][j], (m - j)));
			f[i][j] = add(s[i][j], add(h[i][j], mul(p[m - j][i - 1], i)));
			upd(f[i][j], f[i][j + 1]);
			upd(s[i + 1][j], f[i][j]);
		}
	}
	cout << f[n][1] << endl;
	return 0;
}
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
typedef long long ll;
const int mod=998244353;
int n,m;
void update(int &x,int y) {
	x+=y; if (x>=mod) x-=mod;
}
int mi[5010];
int main() {
	//freopen("1.txt","r",stdin);
	read(n),read(m);
	mi[0]=1;
	for (int i=1;i<5010;i++) mi[i]=(ll)mi[i-1]*m%mod;
	int ans=(ll)mi[n]*n%mod;
	for (int i=1;i<=m;i++) {
		int tmp=1;
		for (int j=1;j<n;j++) {
			update(ans,mod-(ll)(n-j)*tmp%mod*mi[n-j-1]%mod);
			tmp=(ll)tmp*(m-i)%mod;
		}
	}
	printf("%d\n",ans);
	return 0;
}
/*
  0. Enough array size? Enough array size? Enough array size? Integer overflow?
  
  1. Think TWICE, Code ONCE!
  Are there any counterexamples to your algo?
    
  2. Be careful about the BOUNDARIES!
  N=1? P=1? Something about 0?
    
  3. Do not make STUPID MISTAKES!
  Time complexity? Memory usage? Precision error?
*/