#include <bits/stdc++.h>
using namespace std;
const long nPrime = 998244353;
int main() {
    long n,m;
    cin >> n >> m;
    vector<long> viPowSum(n,0);
    vector<long> viPow(m,1);
    for(long i = 0; i < n; i++){
        for(long j = 0; j < m; j++){
            viPowSum[i] += viPow[j];
            viPow[j] *= j;
            viPow[j] %= nPrime;
        }
        viPowSum[i] %= nPrime;
    }
    vector<long> viPowM(n+1,1);
    for(long i = 1; i < n+1; i++){
        viPowM[i] = viPowM[i-1] * m;
        viPowM[i] %= nPrime;
    }
  
    vector<long> viDP(n+1,0);
    for(long i = 1; i < n+1; i++){
        viDP[i] = viDP[i-1] * m;
        long nCount0 = 0;
        for(long j = 0; j < i-1; j++){
            nCount0 += viPowSum[j] * viPowM[i-j-2];
            nCount0 %= nPrime;
        }
        viDP[i] += (viPowM[i] - nCount0);
        viDP[i] %= nPrime;
        if(viDP[i] < 0){
            viDP[i] += nPrime;
        }
    }
    cout << viDP[n] << endl;
}
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> P;

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

template<typename T1,typename T2>ostream& operator<<(ostream& os,const pair<T1,T2>& a) {os << "(" << a.first << ", " << a.second << ")";return os;}

const char newl = '\n';

// const ll mod = 1000000007;
const ll mod = 998244353;

const int MAX_N = 100010;
ll fact[MAX_N],fact_inv[MAX_N],inv[MAX_N];

ll pow_mod(ll a,ll b) {
    ll ret;
    if (b < 0) ret = pow_mod(a,mod+b-1);
    else if (b == 0) ret = 1;
    else if (b == 1) ret = a;
    else {
        ll c = pow_mod(a,b/2);
        if (b%2) ret = (c*c)%mod*a%mod;
        else ret = c*c%mod;
    }
    return ret;
}

void init(int x) {
    fact[0] = 1;fact[1] = 1;
    for (int i = 2;i <= x;++i) fact[i] = fact[i-1]*i%mod;
    fact_inv[x] = pow_mod(fact[x],-1);
    for (int i = x;i > 0;--i) fact_inv[i-1] = fact_inv[i]*i%mod;
    for (int i = 1;i <= x;++i) inv[i] = fact_inv[i]*fact[i-1]%mod;
}

ll combi(ll a, ll b) {
    return fact[a]*fact_inv[b]%mod*fact_inv[a-b]%mod;
}

ll permu(ll a, ll b) {
    return fact[a]*fact_inv[a-b]%mod;
}

int main() {
    int n,m;
    cin >> n >> m;
    vector<vector<ll>> a(m+1,vector<ll>(n+1,1));
    for (int i = 0;i < m+1;++i) for (int j = 0;j < n;++j) a[i][j+1] = a[i][j]*i%mod;
    ll ans = n*a[m][n]%mod;
    for (int i = 1;i < n;++i) for (int j = 0;j < m;++j) {
        (ans -= (n-i)*a[m-j-1][i-1]%mod*a[m][n-i-1]%mod) %= mod;
    }
    cout << (ans+mod)%mod << newl;
}