#include <bits/stdc++.h>

#ifdef mlocal
#include "./Competitive-Code-Library/snippets/prettyprint.h"
#endif
using namespace std;
#define for_(i, s, e) for (int i = s; i < (int) e; i++)
#define for__(i, s, e) for (ll i = s; i < e; i++)
typedef long long ll;
typedef vector<int> vi;
typedef array<int, 2> ii;
#define endl '\n'

vector<ll> phi_1_to_n(int n) {
	vector<ll> phi(n + 1);
	phi[0] = 0;
	phi[1] = 1;
	for (int i = 2; i <= n; i++)
		phi[i] = i;
	
	for (int i = 2; i <= n; i++) {
		if (phi[i] == i) {
			for (int j = i; j <= n; j += i)
				phi[j] -= phi[j] / i;
		}
	}
	
	for_(i, 1, phi.size()) phi[i] += phi[i - 1] - 1;
	
	return phi;
}


int main() {
#ifdef mlocal
	freopen("test.in", "r", stdin);
#endif
	
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int l, r;
	cin >> l >> r;
//	vector<vi> fac(r+1);
	vi spf(r + 1, -1);
	for__(i, 2, r + 1) {
		if (spf[i] == -1) spf[i] = i;
		
		for (ll j = i*i; j <= r; j += i) {
//			fac[j].push_back(i);
			if (spf[i] == i and spf[j] == -1) spf[j] = i;
		}
	}
	
	
	vi pr;
	ll cop = 0, prod = 1;
	int ct = 0;
	int curl;
	
	function<void(int)> count = [&](int p) {
		if (p == pr.size()) {
//			if (ct == 0) return;
			
			ll curr = r / prod - curl / prod;
//			cout << "current factor: " << prod << " -> " << curr << endl;
			
			if (ct % 2) cop -= curr;
			else cop += curr;
			
			return;
		}
		
		count(p + 1);
		ct++;
		prod *= pr[p];
		count(p + 1);
		prod /= pr[p];
		ct--;
	};
	
	ll ans = 0;
	vi mul(r + 1);
	for (int i = r; i >= max(l, 2); i--) { // TODO:_ change Here
		curl = i;
		cop = 0;
		prod = 1;
		ct = 0;
		pr.clear();
		
		int k = i;
		while (k != 1) {
			int p = spf[k];
			pr.push_back(p);
			while ((k % p) == 0) k /= p;
		}
		
		
		count(0);
//		cout << i << " has prime factors: " << pr << " and has " << cop << " coprime greatr values " << endl;
		// increase ans by: all greater values - the ones which are coprime - the ones which are multiple of me
		ans += 2 * ((r - i) - cop - ((r / i) - 1));
//		cout << i << " adding " << (r - i) - cop - ((r / i) - 1) << endl;
	}
	
	cout << ans << endl;
}


#include <bits/stdc++.h>
#define mod 998244353
using namespace std;
const int maxn=500+5;
int n,m;
char s[maxn][maxn];
int main() {
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;++i) scanf("%s",s[i]+1);
	int ans=1;
	for(int i=1;i<=n+m-1;++i) {
		int opt=0,flag1=1,flag2=1;
		for(int j=max(1,i+1-m);j<=min(n,i);++j) {
			if(s[j][i+1-j]=='R') {
				flag2=0;
				if(!opt) opt=1;
				else if(opt!=1) flag1=0;
			}
			else if(s[j][i+1-j]=='B') {
				flag2=0;
				if(!opt) opt=2;
				else if(opt!=2) flag1=0;
			}
		}
		if(!flag1) ans=0;
		else if(flag2) ans=ans*2%mod;
	}
	printf("%d\n",ans);
	return 0;
}