#include<bits/stdc++.h>
using namespace std;
const int N=5005,mod=998244353;
int n,m,ans,f[N][2],g[N][2];
inline int add(int a,int b){
	a+=b;
	return a<mod?a:a-mod;
}
inline int dec(int a,int b){
	a-=b;
	return a<0?a+mod:a;
}
inline int mul(int a,int b){
	return 1LL*a*b%mod;
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++){
		memset(f,0,sizeof(f));
		memset(g,0,sizeof(f));
		f[0][0]=1;
		g[0][0]=0;
		for(int j=1;j<=n;j++){
			f[j][0]=add(mul(f[j-1][0],m-1),mul(f[j-1][1],i-1));
			g[j][0]=add(mul(g[j-1][0],m-1),mul(g[j-1][1],i-1));
			f[j][1]=add(f[j-1][0],mul(f[j-1][1],m-i+1));
			if(j==n){
				j++;
				j--;
			}
			g[j][1]=add(g[j-1][0],f[j-1][0]);
			g[j][1]=add(g[j][1],mul(g[j-1][1],m-i+1));
		}
		ans=add(ans,add(g[n][0],g[n][1]));
	}
	printf("%d\n",ans);
	return 0;
}
#include <stdio.h>
long long  p = 998244353;
long long n, m;
long long d[5001];
long long r[5001];
long long inv[5001];
void makeinv(void) {
	long long arraynumber = sizeof inv / sizeof inv[0];
	inv[1] = 1;
	for (int invcount = 2; invcount < arraynumber; invcount++) {
		inv[invcount] = p - inv[p % invcount] * (p / invcount) % p;
	}
}
int main() {
	makeinv();
	scanf("%lld%lld", &n, &m);
	d[1] = m;
	for (int i = 0; i <= 5000; i++)r[i] = 1;
	for (long long i = 2; i <= n; i++) {
		d[i] = d[i - 1] * m % p;
		for (long long j = 0; j <= 5000; j++)r[j] = r[j] * j % p;
		for (long long j = 1; j <= m; j++) {
			d[i] += p - ((r[m] - r[m - j]) * inv[j]) % p;
		}
		d[i] += r[m] * m;
		d[i] %= p;
	}
	printf("%lld\n", d[n]);
}