#include <cassert>
#include <iostream>
using namespace std;

constexpr int M = 998244353;

long long modexp(int x, long long e, int m) {
    long long ans = 1, p = x % m;
    while (e > 0) {
        if (e % 2 != 0) ans = (ans * p) % m;
        p = (p * p) % m;
        e >>= 1;
    }
    return ans;
}

long long modinv(long long a, long long m) {
    long long x = m, y = a, p = 1, q = 0, r = 0, s = 1;
    while (y != 0) {
        long long u = x / y;
        long long x0 = y; y = x - y * u; x = x0;
        long long r0 = p - r * u, s0 = q - s * u;
        p = r; r = r0; q = s; s = s0;
    }
    return q < 0 ? q + m : q;
}

int main() {
    int n, m; cin >> n >> m;
    long long ans = 0;
    const int mi = modinv(m, M);
    if (n == 1) { cout << m << endl; return 0; }
    for (int v = 1; v <= m; v++) {
        long long p = m - v + 1, q = m - v, mm = modexp(m, n-2, M);
        for (int r = 0; r < n; r++) {
            ans += (p - q) * (r == n - 1 ? 1 : (v - 1) * mm % M) % M;
            p = p * (m - v + 1) % M;
            q = q * (m - v) % M;
            mm = mm * mi % M;
        }
    }
    for (int v = 1; v <= m; v++) {
        long long p = m - v + 1, q = m - v, mm = modexp(m, n-2, M);
        for (int l = n-1; l > 0; l--) {
            ans += (p - q) * (v - 1) % M * mm % M;
            p = p * (m - v + 1) % M;
            q = q * (m - v) % M;
            mm = mm * mi % M;
        }
    }
    if (n > 2) {
        for (int v = 1; v <= m; v++) {
            long long p = m - v + 1, q = m - v, mm = modexp(m, n-3, M);
            for (int d = 0; d <= n-3; d++) {
                ans += ((long long)(n - d - 2) * (v - 1) * (v - 1) % M *
                        (p - q) % M * mm % M);
                p = p * (m - v + 1) % M;
                q = q * (m - v) % M;
                mm = mm * mi % M;
            }
        }
    }
    cout << (ans % M + M) % M << endl;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<typename A, typename B = A> using pr = pair<A, B>;
#define vec vector
#define ar array
#define len(a) ((int)((a).size()))
#define all(a) (a).begin(), (a).end()

const int mod = 998244353;

struct mint {
    int val;

    explicit mint() : val(0) {}
    explicit mint(int val) : val(val) {}

    inline mint operator + (mint m) {
        int sum = val + m.val;
        if (sum >= mod)
            sum -= mod;
        return mint(sum);
    }

    inline mint operator - (mint m) {
        int sum = val - m.val;
        if (sum < 0)
            sum += mod;
        return mint(sum);
    }

    inline mint operator * (mint m) {
        return mint(1ll * val * m.val % mod);
    }

    friend ostream& operator << (ostream &out, mint m) {
        return out << m.val;
    }
};

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

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

    vec<vec<mint>> val(m + 1, vec<mint>(n + 1));
    for (int i = 0; i <= m; i++)
        val[i][0] = mint(1);
    for (int j = 1; j <= n; j++)
        for (int i = 1; i <= m; i++)
            val[i][j] = val[i][j - 1] * mint(i);

    vec<vec<mint>> pref(m + 1, vec<mint>(n + 1));
    for (int j = 0; j <= n; j++) {
        pref[0][j] = val[0][j];
        for (int i = 1; i <= m; i++)
            pref[i][j] = pref[i - 1][j] + val[i][j];
    }

    mint ans = mint(n) * val[m][n];
    for (int i = 0; i < n; i++)
        for (int j = 0; j < i; j++)
            ans = ans - pref[m - 1][i - j - 1] * val[m][n - i + j - 1];
    cout << ans << '\n';
}
