#include <bits/stdc++.h>
using namespace std;

#define co(n) cout<<n<<endl;
const double eps=1e-10,pi=3.1415926535898;
const int mod=998244353,maxn=5e3+10;
int T,n,m,q,k;
long long x,y,a[maxn][maxn];

long long qpow(long long x, int k) {
	long long cnt=1;
	while (k) {
		if (k&1) cnt = cnt*x%mod;
		x = x*x%mod;
		k >>= 1;
	}
	return cnt;
}

int main(int argc, char const *argv[]) {
	for (int i=0;i<maxn;++i) {
		a[i][0] = 1;
	}
	for (int i=0;i<maxn;++i) {
		for (int j=1;j<maxn;++j) {
			a[i][j] = a[i][j-1]*i%mod;
		}
	}
	scanf("%d %d", &n, &m);
	long long ans=qpow(m, n)*n%mod;
	for (int i=1;i<=m;++i) {
		for (int j=0;j<=n-2;++j) {
			ans += mod-a[m][n-j-2]*a[m-i][j]%mod*(n-j-1)%mod;
		}
	}
	printf("%lld\n", ans%mod);
	return 0;
}
#include <bits/stdc++.h>
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, a, b) for (int i = (int)(a); i >= (int)b; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, r, l) for (int i = (r); i >= (l); i--)
#define ms(x, y) memset(x, y, sizeof(x))
#define SZ(x) int(x.size())
#define fk cerr<<"fk"<<endl
#define db(x) cerr<<(#x)<<'='<<(x)<<endl
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
//1.integer overflow (1e5 * 1e5) (2e9 + 2e9)
//2.runtime error
//3.boundary condition
string origin,t;
int n;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout<<fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "r", stdin);
#endif
	origin="";
	forn(i, 2*(int)1e5+100){
		origin+="110";
	}
	cin>>n;
	cin>>t;
	if(t=="1"){
		cout<<2*(i64)1e10<<'\n';
		return 0;
	}
	i64 minn=INT_MAX;
	for(int i=0; i<3; ++i){
		i64 now=i-1;
		bool ok=true;
		forn(j,n){
			++now;
			if(origin[now]!=t[j]){
				ok=false;
				break;
			}
		}
		if(ok) uin(minn,(now+3)/3);
	}
	if(minn==INT_MAX) cout<<0<<'\n';
	else	cout<<(i64)1e10-minn+1<<'\n';
#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}