#include<iostream>
#include<cstdio>
#define mod 998244353
#define N 5000
using namespace std;
long long n,m,ans,dp[N+1][3];
int main()
{
  cin>>n>>m;
  for (int i=1;i<=m;++i)
    {
      for (int j=0;j<=n;++j) dp[j][0]=dp[j][1]=dp[j][2]=0;
      dp[0][1]=1;
      for (int j=1;j<=n;++j) dp[j][2]=(dp[j][2]+dp[j-1][2]*m%mod+dp[j-1][1])%mod,dp[j][1]=(dp[j][1]+dp[j-1][0]*(i-1)%mod+dp[j-1][1]*(m-1)%mod)%mod,dp[j][0]=(dp[j][0]+dp[j-1][0]*(m-i+1)%mod+dp[j-1][1])%mod;
      ans=(ans+dp[n][2])%mod;
    }
  printf("%lld\n",ans);
  return 0;
}

#include <bits/stdc++.h>
#define fi first
#define se second
#define gc getchar() //(p1==p2&&(p2=(p1=buf)+fread(buf,1,size,stdin),p1==p2)?EOF:*p1++)
#define mk make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define IT iterator
#define V vector
#define TP template <class o>
#define TPP template <typename t1, typename t2>
#define SZ(a) ((int)a.size())
#define all(a) a.begin(), a.end()
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define REP(i, a, b) for (int i = b; i >= a; i--)
#define FOR(i, n) rep(i, 1, n)
#define debug(x) cerr << #x << ' ' << '=' << ' ' << x << endl
using namespace std;
typedef unsigned ui;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
const int N = 5010, size = 1 << 20, mod = 998244353, inf = 2e9;
const ll INF = 1e15;

// char buf[size],*p1=buf,*p2=buf;
TP void qr(o& x) {
    char c = gc;
    x = 0;
    int f = 1;
    while (!isdigit(c)) {
        if (c == '-')
            f = -1;
        c = gc;
    }
    while (isdigit(c))
        x = x * 10 + c - '0', c = gc;
    x *= f;
}
template <class o, class... O> void qr(o& x, O&... y) {
    qr(x);
    qr(y...);
}
TP void qw(o x) {
    if (x / 10)
        qw(x / 10);
    putchar(x % 10 + '0');
}
TP void pr1(o x) {
    if (x < 0)
        x = -x, putchar('-');
    qw(x);
    putchar(' ');
}
template <class o, class... O> void pr1(o x, O... y) {
    pr1(x);
    pr1(y...);
}
TP void pr2(o x) {
    if (x < 0)
        x = -x, putchar('-');
    qw(x);
    putchar(10);
}
template <class o, class... O> void pr2(o x, O... y) {
    pr2(x);
    pr2(y...);
}

TP void cmax(o& x, o y) {
    if (x < y)
        x = y;
}
TP void cmin(o& x, o y) {
    if (x > y)
        x = y;
}
TPP void ad(t1& x, t2 y) {
    x += y;
    if (x >= mod)
        x -= mod;
}
TPP void dl(t1& x, t2 y) {
    x -= y;
    if (x < 0)
        x += mod;
}

int n, m;
ll s[N], p[N];

void solve() {
    qr(n, m);
    p[0] = 1;
    FOR(i, n) p[i] = p[i - 1] * m % mod;
    rep(i, 0, m - 1) {
        ll t = 1;
        FOR(j, n) ad(s[j], t), t = t * i % mod;
    }
    ll ans = p[n] * n % mod;
    FOR(i, n) {
        FOR(j, i - 1) { dl(ans, s[i - j] * p[n - (i - j) - 1] % mod); }
    }
    pr2(ans);
}

int main() {
    int T = 1;
    // qr(T);
    while (T--)
        solve();
    return 0;
}