#include <bits/stdc++.h>
#define st first
#define nd second
#define PQ priority_queue
#define MP make_pair

using ll = long long ;
using namespace std;
using pii = pair<int,int>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using pll = pair<ll, ll>;
const int N = 0;
const int MOD = 1e9 + 7;
int mult(int x, int y) {
	return 1LL * x * y % MOD;
}
int f_pow(int val, int id){
	if (id == 0) return 1;
	if (id == 1) return val;
	int k = f_pow(val, id >> 1);
	k = mult(k, k);
	if(id & 1) {
		k = mult(k, val);
	}
	return k;
}
int main(){
	int n, p;
	scanf("%d %d", &n, &p);
	if (p == 2) {
		return !printf("%d", n == 1 ? 1 : 0);
	}
	printf("%d", mult(p - 1, f_pow(p - 2, n - 1)));	


}
#include <bits/stdc++.h>
#define ll long long
#define B break
#define C continue
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define gc getchar
#define pc putchar
#define kg putchar(' ')
#define hh putchar('\n')
#define mem(a,b) memset(a,b,sizeof(a))
#define _for(i,a,b) for( int i=(a); i<=(b); i++)
#define _rep(i,a,b) for( int i=(a); i>=(b); i--)
//#define int __int128
#define int long long
using namespace std;
inline int rd(){
    int x=0,f=1;char ch=gc();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=gc();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=gc();}
    return x*f;
}
char chhh[200];
inline void rt(int x){
    int cnt=0,tmp=x>0?x:-x;
    if (!x) {pc('0');return;}
    if(x<0) pc('-');
    while(tmp>0) {chhh[cnt++]=tmp%10+'0';tmp/=10;}
    while(cnt>0) pc(chhh[--cnt]);
}
const int mod=998244353;
int f[5010],g[5010];
signed main(){
//int main(){
	//int t;
	//t=rd();
	//while(t--){
	int n=rd(),m=rd();
	f[0]=1;
	_for(i,1,n){
		f[i]=f[i-1]*m%mod;
	}
	int ans=f[n]*n%mod;
	_for(i,1,m){
		_for(j,1,n){
			g[j]=(g[j-1]*i+(f[j-1]-g[j-1]+mod))%mod;
			ans=(ans-g[j-1]*f[n-j]+mod*mod)%mod;
		}
	}
	rt(ans);



	//}

    return 0;
}



