#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL<<60;
const double PI = acos(-1.0);
/*const double PI = atan2(0.0,-1.0)*/
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep1(i,aa,n) for(ll i = aa; i <= (ll)(n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define ar_init(aa,val) rep(i,aa.size()) aa[i]=val;
#define v2d(aa,val1,val2,ini) vector<vector<ll>> aa(val1,vector<ll>(val2,ini));
#define pqe priority_queue<ll>
#define pqeg priority_queue<ll,vector<ll>,greater<ll>>
#define lcin(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define eout(...) COU(__VA_ARGS__);
#define sout(...) SCOU(__VA_ARGS__);
#define scin(...) string __VA_ARGS__;CINT(__VA_ARGS__)
#define lb(aa,val) lower_bound(ALL(aa),val)
#define pb push_back
#define mkp make_pair
#define si size()

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}

void COU(){}
template <class Head,class... Tail>
void COU(Head&& head,Tail&&... tail){
    cout<<head<<endl;
    COU(move(tail)...);
}

void SCOU(){}
template <class Head,class... Tail>
void SCOU(Head&& head,Tail&&... tail){
    cout<<head<<" ";
    SCOU(move(tail)...);
}

template <class T = ll>
T IN(){T x;cin>>x;return (x);}

using pii = pair<ll,ll>;
using v2 = vector<vector<ll>>;
using v1 = vector<ll>;
using v2p = vector<vector<pii>>;
using v1p = vector<pii>;
//ll mo=1000000007;
ll mo=998244353;

ll mod_pow(ll N,ll n){
if(n==0) return 1;
ll pp,hh;
pp=n/2;
hh=n%2;
int tt=mod_pow(N,n/2);
if(hh==0)return tt%mo*tt%mo;
else {return tt%mo*tt%mo*N%mo;}
}

ll pp[6000][6000];
int main(){
//cout<<fixed<<setprecision(15);

lcin(n,m);

rep1(i,1,m){
pp[i][0]=1;
rep1(k,1,n){
pp[i][k]=pp[i][k-1]*i;
pp[i][k]%=mo;
}
}

ll res=0;

rep1(i,1,m){
rep1(k,1,n){
if(k+2<=n){res+=pp[m][n-k-2]*(pp[m-i+1][k]-pp[m-i][k])%mo*max((ll)0,n-k+1-2)*(i-1)%mo*(i-1)%mo;
}
if(k!=n){res+=2*pp[m][max((ll)0,n-k-1)]*(pp[m-i+1][k]-pp[m-i][k])%mo*(i-1)%mo;
}
if(k==n){res+=pp[m-i+1][k]-pp[m-i][k];
res%=mo;
}

}
}

eout(res);
}
#define pb push_back
#define mp make_pair
#define fi first
#define se second 
#define all(...) begin(__VA_ARGS__) , end(__VA_ARGS__)
#define boost {ios_base::sync_with_stdio(false); cin.tie(); cout.tie();}

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector <int> vi;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
constexpr ll nax = 2e5+6969, INF = 2e9+6969, mod = 998244353;

ll Pow(ll a, ll b) 
{
	if(b < 0) return 0;
	ll w = 1;
	while(b) 
	{
		if(b&1) w = (w * a) % mod;
		a = (a * a) % mod;
		b >>= 1;
	}
	return w;
}

int main()
{
	ll n,m, ans = 0;
	cin >> n >> m;
	ll last = Pow(m, n-2);
	ll inv = Pow(m, mod - 2);
	
	for(ll x = 1; x <= m; x++) 
	{
		ll A = last, B = 1;
		for(ll d = 1; d < n; d++) 
		{
			ll cur = (n - d) * A % mod * B % mod;
			ans = (ans + cur) % mod;
			//  cout << "For d=" << d << ", x=" << x << " A,B,ans " << A << " " << B << " " << ans << "\n";
			A = (A * inv) % mod;
			B = (B * (m-x)) % mod;
		}
	}
	ans = n * Pow(m, n) - ans;
	ans %= mod;
	if(ans < 0) ans += mod;
	
	cout << ans << "\n";
	
	return 0;
}
