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

#define mod 998244353
typedef long long ll;
int n,m;
ll memo[5005][5005],pwr[5005];

ll exp(int pos,int val){
	if(pos==0)return 1;
	if(memo[pos][val]!=-1)return memo[pos][val];
	return memo[pos][val]=((val-1)*pwr[pos-1]+(m-val)*exp(pos-1,val))%mod;
}

int main(){
	scanf("%d%d",&n,&m);
	pwr[0]=1;
	for(int i=1;i<=n;++i){
		pwr[i]=(pwr[i-1]*m)%mod;
		//printf("%lld ",pwr[i]);
	}
	//printf("\n");
	ll ans=0;
	memset(memo,-1,sizeof memo);
	for(int i=0;i<n;++i){
		for(int j=1;j<=m;++j){
			ans+=exp(i,j)*pwr[n-i-1];
			ans%=mod;
			//printf("%d %d: %lld\n",i,j,exp(i,j));
		}
	}
	printf("%lld\n",ans);
}

// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;

// ModInt begin

using ll = long long;
template<ll mod>
struct ModInt {
    ll v;
    ll mod_pow(ll x, ll n) const {
        return (!n) ? 1 : (mod_pow((x*x)%mod,n/2) * ((n&1)?x:1)) % mod;
    }
    ModInt(ll a = 0) : v((a %= mod) < 0 ? a + mod : a) {}
    ModInt operator+ ( const ModInt& b ) const {
        return (v + b.v >= mod ? ModInt(v + b.v - mod) : ModInt(v + b.v));
    }
    ModInt operator- () const {
        return ModInt(-v);
    }
    ModInt operator- ( const ModInt& b ) const {
        return (v - b.v < 0 ? ModInt(v - b.v + mod) : ModInt(v - b.v));
    }
    ModInt operator* ( const ModInt& b ) const {return (v * b.v) % mod;}
    ModInt operator/ ( const ModInt& b ) const {return (v * mod_pow(b.v, mod-2)) % mod;}
    
    bool operator== ( const ModInt &b ) const {return v == b.v;}
    bool operator!= ( const ModInt &b ) const {return !(*this == b); }
    ModInt& operator+= ( const ModInt &b ) {
        v += b.v;
        if(v >= mod) v -= mod;
        return *this;
    }
    ModInt& operator-= ( const ModInt &b ) {
        v -= b.v;
        if(v < 0) v += mod;
        return *this;
    }
    ModInt& operator*= ( const ModInt &b ) {
        (v *= b.v) %= mod;
        return *this;
    }
    ModInt& operator/= ( const ModInt &b ) {
        (v *= mod_pow(b.v, mod-2)) %= mod;
        return *this;
    }
    ModInt pow(ll x) { return ModInt(mod_pow(v, x)); }
    // operator int() const { return int(v); }
    // operator long long int() const { return v; }
};

template<ll mod>
ModInt<mod> pow(ModInt<mod> n, ll k) {
    return ModInt<mod>(n.mod_pow(n.v, k));
}

template<ll mod>
ostream& operator<< (ostream& out, ModInt<mod> a) {return out << a.v;}
template<ll mod>
istream& operator>> (istream& in, ModInt<mod>& a) {
    in >> a.v;
    return in;
}

// ModInt end

using mint = ModInt<998244353>;

mint tab[5010][5010];
int main() {
    int N, M; cin >> N >> M;

    for(int i=1; i<=M; i++) {
        tab[i][0] = mint(1);
        for(int j=1; j<=N; j++) {
            tab[i][j] = tab[i][j-1] * mint(i);
        }
    }
    mint ans(0);
    for(int len=1; len<=N; len++) {
        // len の両端はそれより低い (len == N なら関係ない)
        // len 内の要素は全て val 以上        
        // len 内の要素に少なくとも 1 つ val の要素が存在
        for(int val=1; val<=M; val++) {
            mint tmp(0);
            mint v = tab[M-val+1][len] - tab[M-val][len];
            if(len < N - 1) {
                // 端の場合 (2 通り)
                tmp += tab[M][N-len-1] * mint(2) * v * mint(val - 1);

                // そうでない場合
                tmp += tab[M][N-len-2] * mint(N-len-1) * v * mint(val-1) * mint(val-1);
            }
            else if(len == N - 1) {
                // 端の場合しかない
                tmp += tab[M][N-len-1] * mint(2) * v * mint(val-1);
            }
            else {
                // それ以上バリエーションなし
                tmp += v;
            }
            ans += tmp;
        }
    }
    cout << ans << endl;
    return 0;
}
