#include <bits/stdc++.h>
using namespace std;
const int md = 998244353;
int n, m, i, j, r;
char s[505][505], c[1010];
void solve() {
    scanf("%d%d", &n, &m);
    for (i = 0; i < n; i++) {
        scanf("%s", s[i]);
        for (j = 0; j < m; j++) if (s[i][j] != '.') {
                if (c[i + j] != 0 && c[i + j] != s[i][j]) { puts("0"); return ;}
                c[i + j] = s[i][j];
            }
    }
    for (r = 1, i = 0; i <= n + m - 2; i++) if (c[i] == 0) r = (r * 2) % md;
    printf("%d\n", r);
}
int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr);
    solve();
    return 0;
}
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mxn = 500+10;
const int mod = 998244353;

ll powmod(ll a, ll b) {
	ll ret = 1;
	while(b) {
		if(b&1ll) ret*=a, ret%=mod;
		a*=a; a%=mod; b>>=1;
	}
	return ret;
}

map<char, int> diag[2*mxn];

signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0);

	int n, m; cin>>n>>m;
	for(int i=0; i<n; i++) for(int j=0; j<m; j++) {
		char c; cin>>c; diag[i+j][c]++;
	}

	ll ans = 1;
	for(int i=0; i<n+m-1; i++) {
		if(diag[i].count('R') and diag[i].count('B')) {
			ans = 0; break;
		}
		if(diag[i].count('R') or diag[i].count('B')) continue;
		ans*=2; ans%=mod;
 	}

 	cout << ans << '\n';
	return 0;
}

