#define taskname "test"

#include <bits/stdc++.h>

using namespace std;

#define sz(x) (int)x.size()
#define fi first
#define se second

typedef long long lli;
typedef pair<int, int> pii;

const int maxn = 5005;
const int mod = 998244353;

int n, m;
int a[maxn][maxn];

int f[maxn];

int g[maxn];

void read_input()
{
    cin >> n >> m;
}

int powmod(int x, int k)
{
    return a[x][k];
}

int add(int x, int y)
{
    x += y;
    if(x >= mod) x -= mod;
    return x;
}

int sub(int x, int y)
{
    x -= y;
    if(x < 0) x += mod;
    return x;
}

void solve()
{
    for(int i = 0; i <= m; ++i)
    {
        a[i][0] = 1;
        for(int j = 1; j <= n; ++j)
            a[i][j] = a[i][j - 1] * 1LL * i % mod;
    }
    f[1] = m;
    fill(g + 1, g + m + 1, 1);
    for(int i = 2; i <= n; ++i)
    {
        f[i] = f[i - 1] * 1LL * m % mod;
        for(int j = 1; j <= m; ++j)
            f[i] = add(f[i], sub(powmod(m, i - 1), g[j]));
        for(int j = 1; j <= m; ++j)
        {
            g[j] = g[j] * 1LL * m % mod;
            g[j] = add(g[j], powmod(m - j, i - 1));
        }
    }
    cout << f[n] << '\n';
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    read_input();
    solve();
}


#include<bits/stdc++.h>
#define int long long
using namespace std;
int prm[20]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71},f[74][1<<20],a,b,c[74],ans;
signed main()
{
	cin>>a>>b;
	//cout<<b-a+1<<endl;
	for(register int i=a;i<=b;i++)
	{
		for(register int j=0;j<20;j++)
		{
			if(i%prm[j]==0)c[i-a+1]|=1<<j;
		}
		//cout<<c[i-a+1]<<endl;
	}
	//cout<<'*';
	f[0][0]=1;
	for(register int i=1;i<=b-a+1;i++)
	{
		memcpy(f[i],f[i-1],sizeof(f[i]));
		//cout<<'*';
		for(register int j=0;j<(1<<20);j++)
		{
			if(j&c[i]||!f[i-1][j])continue;
			//printf("%lld\n",j|c[i-a+1]);
			f[i][j|c[i]]+=f[i-1][j];
		}
	}
	for(register int i=0;i<(1<<20);i++)ans+=f[b-a+1][i];
	cout<<ans;
	return 0;
}