#include <bits/stdc++.h>

using namespace std;
const int c=5002;
long long n, m, sum, mod=998244353;
long long po[c][c];
int main()
{
    ios_base::sync_with_stdio(false);
    cin >> n >> m;
    for (int i=0; i<=m; i++) {
        po[i][0]=1;
    }
    for (int i=0; i<=m; i++) {
        for (int j=1; j<=n; j++) {
            po[i][j]=po[i][j-1]*i%mod;
        }
    }
    sum=po[m][n]*n%mod;
    for (int i=1; i<n; i++) {
        for (int j=1; j<=m; j++) {
            sum-=(n-i)*po[m][n-i-1]%mod*po[m-j][i-1]%mod;
        }
    }
    sum%=mod;
    if (sum<0) {
        sum+=mod;
    }
    cout << sum << "\n";
    return 0;
}

#include <bits/stdc++.h>

#define fi first
#define se second
#define DB double
#define U unsigned
#define P std::pair
#define LL long long
#define LD long double
#define pb emplace_back
#define MP std::make_pair
#define SZ(x) ((int)x.size())
#define all(x) x.begin(),x.end()
#define CLR(i,a) memset(i,a,sizeof(i))
#define FOR(i,a,b) for(int i = a;i <= b;++i)
#define ROF(i,a,b) for(int i = a;i >= b;--i)
#define DEBUG(x) std::cerr << #x << '=' << x << std::endl

const int MAXN = 5000+5;
const int ha = 998244353;
int n,m;

inline void add(int &x,int y){
    x += y-ha;x += x>>31&ha;
}

int pw[MAXN],pw1[MAXN];

int main(){
    scanf("%d%d",&n,&m);
    if(m == 1){
        puts("1");
        return 0;
    }
    pw[0] = 1;FOR(i,1,MAXN-1) pw[i] = 1ll*pw[i-1]*m%ha;
    pw1[0] = 1;FOR(i,1,MAXN-1) pw1[i] = 1ll*pw1[i-1]*(m-1)%ha;
    int ans = 0;
    FOR(x,2,m){
        int c = 1;
        FOR(k,2,n-1){
            c = 1ll*c*(m-x)%ha;
            int d = (pw1[k-1]+ha-c)%ha;
            add(ans,1ll*d*(n-k)%ha*pw[n-(k+1)]%ha);
        }
    }
    FOR(i,1,n) add(ans,1ll*pw1[i-1]*pw[n-i+1]%ha);
    printf("%d\n",ans);
    return 0;
}
