#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
const int N = 5005;
const int mod = 998244353;
using namespace std;

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

template < typename T >
inline T read()
{
	 T x = 0, w = 1; char c = getchar();
	 while(c < '0' || c > '9') { if(c == '-') w = -1; c = getchar(); }
	 while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	 return x * w; 
}

int fpow(int x, int y)
{
	 int res = 1;
	 for( ; y; y >>= 1, x = 1ll * x * x % mod)
		  if(y & 1) res = 1ll * res * x % mod;
	 return res;
}

int main()
{
#ifndef ONLINE_JUDGE
	 freopen("cpp.in", "r", stdin);
#endif
	 n = read <int> (), m = read <int> ();
	 for(int c = 1; c <= m; c++)
		  for(int res = 1, k = 0; k <= n; k++)
				f[k] = (f[k] + res) % mod, res = 1ll * res * (m - c) % mod;
	 for(int i = (pw[0] = 1); i <= n; i++) pw[i] = 1ll * pw[i - 1] * m % mod;
	 for(int i = 1; i <= n; i++)
		  for(int k = 0; k <= i - 2; k++)
				ans = (1ll * f[k] * pw[n - 2 - k] + ans) % mod;
	 ans = (1ll * n * fpow(m, n) - ans + mod) % mod;
	 printf("%d\n", ans);
	 return 0; 
}

#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
//#define MOD 1000000007LL
#define MOD 998244353LL
#define doublecout(a) cout<<setprecision(16)<<a<<endl;
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
using vvvi = vector<vvi>; // intの2次元の型に vvi という別名をつける
const ll llMAX=9223372036854775807LL; 
const ll llMIN=-9223372036854775808LL;

void myprint1D(vi &data)
{
  REP(i,data.size())
    cout<<data[i]<<" ";
  cout<<endl;
}

//配列を[y][x]で表示
void myprint2D_T(vvi &data)
{
  REP(i,data.size())
    myprint1D(data[i]);
}

//配列を[x][y]で表示
void myprint2D(vvi &data)
{
  ll l1=data.size();
  ll l2=data[0].size();
  REP(j,l2){
    REP(i,l1)
      cout<<data[i][j]<<" ";
    cout<<endl;
  }
}

//print(a,b...)って使い方
void print1(ll a){cout<<a<<endl;}
void print2(ll a,ll b){cout<<a<<" "<<b<<endl;}
void print3(ll a,ll b,ll c){cout<<a<<" "<<b<<" "<<c<<endl;}
void print4(ll a,ll b,ll c,ll d){cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;}
void print5(ll a,ll b,ll c,ll d,ll e){cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<e<<endl;}


//moddivとnCkとgarner
ll gcd(ll a,ll b){
  ll r = a % b;
  while(r!=0LL){
    a = b;
    b = r;
    r = a % b;
  }
return b;
}

//c剰余下でaをbで割った値
ll moddiv(ll a,ll b,ll c){
	ll x0=c,x1=b,x2,n0=0LL,n1=1LL,n2,t=a%b,m,ans;
	if (t==0LL) return a/b;
		for(int i=0;i<900;i++){
      m=x0/x1;
      x2=x0-x1*m;
      n2=(n0-m*n1)%c;
      if (x2==1LL){
        ans=(n2+c)%c;
        break;
      }
      x0=x1;x1=x2;
      n0=n1;n1=n2;
    }
	return (a+((t*ans)%c)*b-t)/b;
}
//剰余の割ざん

//aのn乗 mod c
ll expmod(ll a,ll n,ll c){
  ll ans=1LL,aa=a,beki=n;
  for(int i=0;i<64;i++){
    if (beki%2==1LL) ans=ans*aa%c;
    aa=aa*aa%c;
    beki/=2LL;
    if (beki==0LL)break;
  }
  return ans;
}

//nCk
vi mulmod(500001);//0!,1!,2!,3!,4!,,,,
void first_nCk(){
  mulmod[0]=1LL;
  for(ll i=1;i<500001;i++){
    mulmod[i]=mulmod[i-1]*i%MOD;
  }
}
ll nCk(ll nn,ll kk){
  return moddiv(mulmod[nn],mulmod[kk]*mulmod[nn-kk]%MOD,MOD);
}
ll modinv(ll a,ll b){
  return moddiv(1,a%b,b);
}

//条件ar<a,br<b
ll garner(__int128_t a,__int128_t b,__int128_t ar,__int128_t br){
  if (gcd(a,b)==1){
    if (a==1){
      return br;
    }
    if (b==1){
      return ar;
    }
    
    __int128_t tmp=(br-ar)%b*modinv(a,b)%b;
    if (tmp<0)tmp+=b;
    return ar+tmp*a;
  }else{//299%200=99,299%300=299とかのとき
    //ありえない場合-1を出力
    __int128_t g=gcd(a,b);
    if (ar>br){
      __int128_t rr=ar-br;
      if (rr%g!=0){
        return -1;
      }
      __int128_t rrg=rr/g;
      __int128_t ret=garner(a/g,b/g,rrg,0);
      return ret*g+br;
    }else{
      __int128_t rr=br-ar;
      if (rr%g!=0){
        return -1;
      }
      __int128_t rrg=rr/g;
      __int128_t ret=garner(a/g,b/g,0,rrg);
      return ret*g+ar;
    }
  }
}




ll n,m;

int main(){
  ll ans=0;
  cin >> n >> m;
  vi data(m);  // N * M の2次元配列
  vi gk(m,0);
  vi expmi1(n);
  for(ll i=1;i<n;i++){
    expmi1[i]=expmod(m,i-1,MOD);
  }

  ll lastsmm=0;
  ll smm=0;
  for(ll i=1;i<n;i++){
    lastsmm=smm%MOD;
    smm=0;
    for(ll j=0;j<m;j++){
      gk[j]*=m-j-1;
      gk[j]+=expmi1[i];
      gk[j]%=MOD;
      ll score=lastsmm+gk[j];
      data[j]=score%MOD;
      smm+=data[j];
    }
  }

  //myprint2D(data);

  ans=expmod(m,n,MOD)*n;
  for(ll j=0;j<m;j++){
    ans-=data[j];
  }
  ans=(ans%MOD+MOD)%MOD;

  cout<<ans<<endl;
  return 0;
}