# pragma GCC optimize ("O3")
# pragma GCC optimize ("Ofast")
# pragma GCC optimize ("unroll-loops")
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i < (b); i++)
#define rep2(i,a,b) for(int i = (b) - 1; i >= (a); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define pb push_back
#define x first
#define y second
using namespace std;
using ll = long long;
using tl = tuple<ll, ll, ll, ll>;
using pl = pair<ll, ll>;
using pi = pair<int, int>;
using ld = long double;

const int MOD = 998244353;
template<class T> struct mi {
	T val;
	mi() { val = 0; }
	mi(const ll& v) {
		val = (-MOD <= v && v <= MOD) ? v : v % MOD;
		if (val < 0) val += MOD;
	}
	mi operator + (const mi& m) {
		T tmp = (val + m.val) % MOD;
		return tmp + (tmp < 0 ? MOD : 0);
	}
	mi operator - (const mi& m) {
		T tmp = (val - m.val) % MOD;
		return tmp + (tmp < 0 ? MOD : 0);
	}
	mi operator * (const mi& m) {
		T tmp = (val * m.val) % MOD;
		return tmp;
	}
	mi& operator += (const mi& m) {
		if ((val += m.val) >= MOD) val -= MOD;
		return *this;
	}
	mi& operator -= (const mi& m) {
		if ((val -= m.val) < 0) val += MOD;
		return *this;
	}
	mi& operator *= (const mi& m) {
		val = (val * m.val) % MOD;
		return *this;
	}
};
ll N, M;
mi<ll> ans, mpow[5001][5001];

int main() {
    cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
    cin >> N >> M;
	rep(i, 0, M + 1) mpow[i][0] = 1;
	rep(i, 0, M + 1) rep(j, 1, N + 1) mpow[i][j] = mpow[i][j - 1] * i;
	ans = mpow[M][N] * N;
	rep(s, 1, N){
		mi<ll> tmp(0);
		rep(x, 1, M + 1) tmp += mpow[M - x][s - 1];
		ans -= tmp * mpow[M][N - s - 1] * (N - s);
	}
	cout << ans.val << endl;
}

#include "bits/stdc++.h"
#define int long long
#define endl '\n'
using namespace std;
 
typedef long long ll;
typedef long double ld;
#define db(x) cerr << #x << ": " << x << '\n';
#define read(a) int a; cin >> a;
#define reads(s) string s; cin >> s;
#define readb(a, b) int a, b; cin >> a >> b;
#define readc(a, b, c) int a, b, c; cin >> a >> b >> c;
#define readarr(a, n) int a[(n) + 1] = {}; FOR(i, 1, (n)) {cin >> a[i];}
#define readmat(a, n, m) int a[n + 1][m + 1] = {}; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}

#define print(a) cout << a << endl;
#define printarr(a, n) FOR (i, 1, n) cout << a[i] << " "; cout << endl;
#define printv(v) for (int i: v) cout << i << " "; cout << endl;
#define printmat(a, n, m) FOR (i, 1, n) {FOR (j, 1, m) cout << a[i][j] << " "; cout << endl;}
#define all(v) v.begin(), v.end()
#define sz(v) (int)(v.size())
#define rz(v, n) v.resize((n) + 1);
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define vpi vector <pi>
#define vvi vector <vi>
#define setprec cout << fixed << showpoint << setprecision(20);
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
const ll inf = 1e18;
const ll mod = 998244353;
const ll N = 2e5 + 1;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int power (int a, int b = mod - 2)
{
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return res;
}

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	readb(n, m);
	int one[n + 1][m + 1] = {}, zer[n + 1][m + 1] = {};
	int onesum[n + 1][m + 1] = {}, zersum[n + 1][m + 1] = {};
	
	int precalc[m + 1][n + 1] = {};
	FOR (i, 1, m) precalc[i][0] = 1;
	FOR (i, 1, m)
	    FOR (j, 1, n)
	        precalc[i][j] = i*precalc[i][j - 1] % mod;
	        
	FOR (i, 1, n)
	    FOR (j, 1, m)
	    {
	        one[i][j] = (one[i][j - 1] + onesum[i - 1][j - 1] + zersum[i - 1][j - 1] + precalc[j][i] - precalc[j - 1][i]) % mod;
	        zer[i][j] = (one[i][j] + onesum[i - 1][j] + zersum[i - 1][j]) % mod;
	        
	        onesum[i][j] = (onesum[i - 1][j]*(j + 1) + one[i][j]) % mod;
	        zersum[i][j] = (zersum[i - 1][j]*j + zer[i][j]) % mod;
	    }
	    
    print((one[n][m] + 5*mod) % mod);
}

















