#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#define int long long
#define mid (l+r>>1)
using namespace std;
int read(){
	int x = 1,a = 0;char ch = getchar();
	while (ch < '0'||ch > '9'){if (ch == '-') x = -1;ch = getchar();}
	while (ch >= '0'&&ch <= '9'){a = a*10+ch-'0';ch = getchar();}
	return x*a; 
}
const int maxn = 505,mod = 998244353;
int n,m;
char s[maxn][maxn];
int dp[maxn][maxn][5],a[maxn][maxn];
signed main(){
	n = read(),m = read();
	for (int i = 1;i <= n;i++) scanf ("%s",s[i]+1);
	for (int i = 1;i <= n;i++) for (int j = 1;j <= m;j++){
		if (s[i][j] == 'R') a[i][j] = 0;
		else if (s[i][j] == 'B') a[i][j] = 1;
		else a[i][j] = 2;
	}
//	for (int i = 1;i <= n;i++){ for (int j = 1;j <= m;j++) cout<<a[i][j]<<" ";
//	cout<<endl;}
	for (int i = 1;i <= n;i++){
		for (int j = m;j >= 1;j--){
			dp[i][j][a[i][j]] = 1;
			if (i > 1&&j < m) dp[i][j][0] |= dp[i-1][j+1][0],dp[i][j][1] |= dp[i-1][j+1][1];
		}
	}
	int res = 0;
	for (int i = 1;i <= n;i++){
		if (!dp[i][1][0]&&!dp[i][1][1]) res++;
		if (dp[i][1][0]&&dp[i][1][1]){
			printf("0\n");
			return 0;
		}
	}
	for (int i = 2;i <= m;i++){
	//	cout<<dp[n][i][0]<<" "<<dp[n][i][1]<<endl;
		if (!dp[n][i][0]&&!dp[n][i][1]) res++;
		if (dp[n][i][1]&&dp[n][i][0]){
			printf("0\n");
			return 0;
		}
	}
	int ans = 1;
//	cout<<res<<endl;
	for (int i = 1;i <= res;i++) ans = 1ll*2*ans % mod;
	printf("%lld\n",ans);
	return 0;
}
#include <iostream>
#include <bits/stdc++.h>
#define int long long
#define endl '\n' 
using namespace std;
string p[520];
signed main(){	
	int mx = 0;
	int h,w;
	cin >> h >> w;
	int ans = 1;
	for(int i = 0;i < h;i++){
		cin >> p[i];
	}
	
	bool able = true;
	for(int i = 0;i < w;i++){
		int sti = i;
		int stj = 0;
		bool c = true;
		int cnt = 0;
		map<char,int> mp;
		while(sti >= 0 && stj < h){
			if(p[stj][sti] != '.'){
				if(mp[p[stj][sti]] == 0){
					cnt += 1;
					mp[p[stj][sti]] = 1;
					if(cnt == 2)able = false;
				}
				c = false;
			}
			sti--;
			stj++;
		}
		if(c) ans = (ans * 2ll)% 998244353;
	}
	for(int i = 1;i < h;i++){
		int sti = w - 1;
		int stj = i;
		bool c = true;
		int cnt = 0;
		map<char,int> mp;
		while(sti >= 0 && stj < h){
			if(p[stj][sti] != '.'){
				if(mp[p[stj][sti]] == 0){
					cnt += 1;
					mp[p[stj][sti]] = 1;
					if(cnt == 2)able = false;
				}
				c = false;
			}
			sti--;
			stj++;
		}
		if(c) ans = (ans * 2ll)% 998244353;
	}
	if(able == true)cout << ans << endl;
	else cout << 0 << endl;
}