#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef	long long ll;
typedef long double ld;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef set<int> si;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef vector<pii> vii;
typedef vector<pll> vll;
#define fi first
#define se second
#define pi 3.141592653589793
#define mod 998244353
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define pqmax priority_queue<int>
#define pqmin priority_queue<int,vi,greater<int>>
#define fio ios_base::sync_with_stdio(0), cin.tie(NULL)
#define tc int tt;cin>>tt;for(int ti=1;ti<=tt;ti++)
#define case_g "Case #"<<ti<<": "
#define RED "\033[31m"
#define GREEN "\033[32m"
#define RESET "\033[0m"
#define sleep for (int i = 1, a;i < 100000000;i++, a = a * a)
typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> ranked_pairset;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ranked_set;
typedef tree<int, int, less<int>, rb_tree_tag, tree_order_statistics_node_update> ranked_map;

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

ll modinv(ll a) {
	ll m = mod, y = 0, x = 1;
	while (a > 1) {
		ll q = a / m, t = m;
		m = a % m;
		a = t;
		t = y;
		y = x - q * y;
		x = t;
	}
	return x < 0 ? x + mod : x;
}

int main() {
	fio;
	ll n, m;
	cin >> n >> m;
	ll dp[n][m];
	for (int i = 0;i < m;i++)
		dp[0][i] = 1;
	vl s(n), minv(m + 1), mpm1j(m, 1);
	s[0] = m;
	mpm1j[0] = 0;
	ll mpmi = 1;
	for (int j = 1;j <= m;j++)
		minv[j] = modinv(j);
	for (int i = 1;i < n;i++) {
		mpmi = mpmi * m % mod;
		for (int j = 0;j < m;j++) {
			mpm1j[m - 1 - j] = mpm1j[m - 1 - j] * (m - 1 - j) % mod;
			dp[i][j] = (s[i - 1] + (mpmi * j + mpm1j[m - 1 - j]) % mod * minv[j + 1]) % mod;
		}
		for (int j = 0;j < m;j++)
			s[i] = (s[i] + dp[i][j]) % mod;
	}
	cout << s[n - 1] << '\n';
}

#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e3+5,mod = 998244353;
int n,m,powm[maxn][maxn],ans;
int main(){
	scanf("%d %d",&n,&m);
	powm[0][0] = 1;
	for(int i=1;i<=m;++i){
		powm[i][0] = 1;
		for(int j=1;j<=n;++j)powm[i][j] = 1ll*powm[i][j-1]*i%mod;
	}
	ans = 1ll*n*powm[m][n]%mod;
	for(int i=1;i<n;++i)
		for(int j=1;j<=m;++j)
			ans -= 1ll*(n-i)*powm[m-j][i-1]%mod*powm[m][n-i-1]%mod,ans = (ans+mod)%mod;
	printf("%d",ans);
	return 0;
}
