#include <bits/stdc++.h>
using namespace std;
#define fast_io cin.tie(0);ios_base::sync_with_stdio(0);
string to_string(string s) { return '"' + s + '"';}
string to_string(char s) { return string(1, s);}
string to_string(const char* s) { return to_string((string) s);}
string to_string(bool b) { return (b ? "true" : "false");}
template <typename A> string to_string(A);
template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
template <typename A> string to_string(A v) {bool f = 1; string r = "{"; for (const auto &x : v) {if (!f)r += ", "; f = 0; r += to_string(x);} return r + "}";}
void debug_out() { cout << endl; }
void show() { cout << endl; }
void pret() { cout << endl; exit(0);}
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cout << " " << to_string(H); debug_out(T...);}
template <typename Head, typename... Tail> void show(Head H, Tail... T) {cout <<H<<" "; show(T...);}
template <typename Head, typename... Tail> void pret(Head H, Tail... T) {cout <<H<<" "; pret(T...);}
#define pr(...) cout << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
typedef long long ll;
#define int ll
typedef long double ld;
typedef vector<int> vi;
#define disp(x) cout<<x<<" ";
#define rep(i,a,b) for(int i=a;i<(int)b;i++)
#define fo(i,a,b) for(int i=a;i<=(int)b;i++)
#define rf(i,a,b) for(int i=a;i>=(int)b;i--)
#define mp make_pair
#define pb emplace_back
#define F first
#define S second
#define endl '\n'
//cout.setf(ios::fixed);cout.precision(18)
const int MOD = 998244353;
const int maxn = 500+10;
const int red = 1;
const int blue = 2;

int a[maxn][maxn];

int32_t main(){
    fast_io;
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n; ++i)
    {
    	string s;
    	cin >> s;
    	for (int j = 0; j < m; ++j)
    	{
    		if(s[j] == 'R') a[i][j] = red;
    		else if(s[j] == 'B') a[i][j] = blue;
    	}
    }
    int ans = 1;
    for (int i = 0; i < n + m - 1; ++i)
    {
    	int r = 0, b = 0, avail = 0;
    	fo(j, 0, i){
    		int x = j, y = i - j;
    		if(x < 0 or x >= n or y < 0 or y >= m) continue;
    		if(a[x][y] == red) r++;
    		else if(a[x][y] == blue) b++;
    		else avail++;
    	}
    	if(r and b) {
    		pret(0);
    	}
    	if(avail){
    		if(r == 0 and b == 0){
    			ans = (ans * 2) % MOD;
    		}
    	}
    }
    show(ans);
    return 0;
}
#include<bits/stdc++.h>
#define cs const
#define pb push_back
using namespace std;
typedef long long ll;
cs int N = 505; 
int n, m; char mp[N][N];
int c[N << 1];
int main() {
	#ifdef FSYo
	freopen("1.in", "r", stdin);
	#endif
	cin >> n >> m; 
	for(int i = 1; i <= n; i++) 
		scanf("%s", mp[i] + 1);
	memset(c, -1, sizeof c);
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++) {
			if(mp[i][j] == 'R'){
				if(c[i + j] == 1) 
					return puts("0"), 0;
				c[i + j] = 0;
			}
 			if(mp[i][j] == 'B') {
 				if(c[i + j] == 0) 
 					return puts("0"), 0;
 				c[i + j] = 1; 
 			}
 		}
	}
	int ans = 1; 
	for(int i = 2; i <= n + m; i++)
	if(c[i] == -1) ans = (ans + ans) % 998244353;
	cout << ans; 
	return 0; 
}