#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 998244353; 

struct fast_io {
	fast_io(){
		std::cin.tie(nullptr);
		std::ios::sync_with_stdio(false);
	};
} fio;

signed main(){
	cout<<fixed<<setprecision(10);
	
	int ans = 1;
	int H, W;
	vector<string> S;
	vector<vector<int>> con;
	
	cin>>H>>W;
	
	S.resize(H);
	con.resize(H+W+1,vector<int>(3));
	
	for(int i = 0; i < H; i++){
		cin>>S[i];
		
		for(int j = 0; j < W; j++) {
			if(S[i][j] == 'R') {
				con[i+j][0]++;
			} else if(S[i][j] == 'B'){
				con[i+j][1]++;
			} else {
				con[i+j][2]++;
			}
		}
	}
	
	for(int i = 0; i+1 < H+W; i++){
		if(con[i][0] && con[i][1]) {
			ans = 0;
		} else if(con[i][0] || con[i][1]) {
			ans *= 1;
		} else {
			// cout<<i<<endl;
			ans *= 2;
		}
		ans %= MOD;
	}
	
	cout<<ans<<endl;
	
	return 0;
}
#include<stdio.h>
#include<iostream>
using namespace std;
const int maxH=505,mod=998244353;
int H,W,ans;
int val[maxH<<1];
string s;
int main(){
	scanf("%d%d",&H,&W);
	for(int i=1;i<=H;i++){
		cin>>s;
		for(int j=1;j<=W;j++)
			val[i+j]|=(s[j-1]=='R'? 1:(s[j-1]=='B'? 2:0));
	}
	ans=1;
	for(int i=2;i<=H+W;i++){
		if(val[i]==3){
			puts("0");
			return 0;
		}
		else ans=1ll*ans*(val[i]==0? 2ll:1ll)%mod;
	}
	printf("%d\n",ans);
	return 0;
}