#include<bits/stdc++.h>
#define pi 3.141592653589793238
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define MOD 1000000007
#define INF 999999999999999999 
#define pb push_back
#define ff first
#define ss second
 
#define mt make_tuple
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
 
 
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
 
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
const int N = 5e3 + 1;
ll n, m; 
ll p[N][N];
ll d[N][N];
ll s[N];
int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    fast;
    ll T = 1, i, j;
    
    //cin >> T;
    while (T--) {
        ll mod = 998244353;
        cin >> n >> m;
        if(m == 1){
            cout << 1 << endl;
            return 0;
        }
        p[0][0] = 1;
        for(i = 1; i <= m; i++){
            p[i][0] = 1;
            for(j = 1; j <= n; j++){
                p[i][j] = (p[i][j - 1] * i) % mod;
            }
        }
        for(i = 2; i <= n; i++){
            for(j = 1; j <= m; j++){
                d[i][j] = p[m - 1][i - 2] - p[m - j][i - 2];
                d[i][j] %= mod;
                d[i][j] += mod;
                d[i][j] %= mod;
            }
        }
        for(i = 1; i <= m; i++){
            for(j = 2; j <= n; j++){
                s[j] += d[j][i];
                s[j] %= mod;
            }
        }
        vector<ll> dp(n + 1);
        dp[1] = m;
        for(i = 2; i <= n; i++){
            //cout << i << "##\n";
            dp[i] += m * dp[i - 1];
            //cout << dp[i] << endl;
            dp[i] %= mod;
            dp[i] += m * (p[m - 1][i - 1]);
            dp[i] %= mod;
            // for(j = 1; j <= m; j++){
            //     dp[i] += (p[m - 1][i - 1]);
            //     ll l = 0;
            //     for(ll k = i - 1; k >= 1; k--){
            //         dp[i] += (p[m][k - 1]) * (p[m - 1][l] - p[m - j][l]);
            //         dp[i] %= mod;
            //         l++;
            //     }
            //     //cout << dp[i] << endl;
            // }
            for(j = i - 1; j >= 1; j--){
                dp[i] += p[m][j - 1] * s[i - j + 1];
                dp[i] %= mod;
            }
        }
        cout << dp[n] << endl;
    }
    return 0;
}
#include <bits/stdc++.h>
using namespace std;

template<int M>
struct static_mint {
	static_assert(0 < M, "Module must be positive");

	int val;
	static_mint(): val() {}
	static_mint(long long x) : val(x % M) { if (val < 0) val += M; }
	static_mint pow(long long n) const { static_mint ans = 1, x(*this); while (n) { if (n & 1) ans *= x; x *= x; n /= 2; } return ans; }
	static_mint inv() const { return pow(M - 2); }

	friend static_mint pow(const static_mint &m, long long n) { return m.pow(n); }
	friend static_mint inv(const static_mint &m) { return m.inv(); }

	static_mint operator+() const { static_mint m; m.val = val; return m; }
	static_mint operator-() const { static_mint m; m.val = M - val; return m; }
	static_mint &operator+=(const static_mint &m) { if ((val += m.val) >= M) val -= M; return *this; }
	static_mint &operator-=(const static_mint &m) { if ((val -= m.val) < 0) val += M; return *this; }
	static_mint &operator*=(const static_mint &m) { val = (long long) val * m.val % M; return *this; }
	static_mint &operator/=(const static_mint &m) { val = (long long) val * m.inv().val % M; return *this; }

	friend static_mint operator+ (const static_mint &lhs, const static_mint &rhs) { return static_mint(lhs) += rhs; }
	friend static_mint operator- (const static_mint &lhs, const static_mint &rhs) { return static_mint(lhs) -= rhs; }
	friend static_mint operator* (const static_mint &lhs, const static_mint &rhs) { return static_mint(lhs) *= rhs; }
	friend static_mint operator/ (const static_mint &lhs, const static_mint &rhs) { return static_mint(lhs) /= rhs; }
	friend bool operator==(const static_mint &lhs, const static_mint &rhs) { return lhs.val == rhs.val; }
	friend bool operator!=(const static_mint &lhs, const static_mint &rhs) { return lhs.val != rhs.val; }

	static_mint &operator++() { return *this += 1; }
	static_mint &operator--() { return *this -= 1; }
	static_mint operator++(int) { static_mint result(*this); *this += 1; return result; }
	static_mint operator--(int) { static_mint result(*this); *this -= 1; return result; }

	template <typename T> explicit operator T() const { return T(val); }

	friend std::ostream &operator<<(std::ostream &os, const static_mint &m) {
		return os << m.val;
	}

	friend std::istream &operator>>(std::istream &is, static_mint &m) {
		long long x; is >> x; m = x;
		return is;
	}
};

template <typename>
struct is_mint : public std::false_type { };

template <int M>
struct is_mint<static_mint<M>> : public std::true_type { };

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	using mint = static_mint<998244353>;

	int n, m;
	cin >> n >> m;

	vector<vector<mint>> pw(m + 1, vector<mint>(n + 1));
	for (int i = 0; i <= m; i++) {
		pw[i][0] = 1;
		for (int j = 1; j <= n; j++) {
			pw[i][j] = i * pw[i][j - 1];
		}
	}

	mint ans = n * pw[m][n];
	for (int l = 2; l <= n; l++) {
		mint temp = 0;
		for (int x = 1; x <= m; x++) {
			temp += pw[m - x][l - 2];
		}
		ans -= (n - l + 1) * temp * pw[m][n - l];
	}
	cout << ans << '\n';
	return 0;
}