#include <bits/stdc++.h>
using namespace std;
using ll=long long;
ll mod=998244353;

int main(){
    int H,W;
    cin>>H>>W;
    vector<string> S(H);
    for(int i=0;i<H;i++) cin>>S[i];
    vector<int> r(H+W,0),b(H+W,0),w(H+W,0);
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(S[i][j]=='R') r[i+j]++;
            if(S[i][j]=='B') b[i+j]++;
            if(S[i][j]=='.') w[i+j]++;
        }
    }
    ll ans=1;
    for(int i=0;i<H+W;i++){
        if(r[i]>0&&b[i]>0) ans=0;
        if(w[i]>0&&r[i]==0&&b[i]==0) ans*=2;
        ans%=mod;
    }
    cout<<ans<<endl;
    return 0;
}
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <array>
#include <random>
#include <cmath>
#include <list>
#include <ctime>
#include <sstream>
#include <queue>
#include <climits>
#include <stack>
#include <random>
#include <bitset>
#include <numeric>
#include <cassert>
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;
#define rep(x, b, e) for(int x=(b); x<(e); ++x)
#define trav(a, x) for(auto& a : x)
#define ford(x, b, e) for(int x=((int)(b))-1; x>=(e); --x)
#define all(c) c.begin(),c.end()
#define sz(x) ((int)((x).size()))
#define pb push_back
#define st first
#define nd second
#define mp(x,y) make_pair(x,y)
typedef short int sint;

#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	int h, w;
	cin >> h >> w;
	vector<string> s(h);
	rep(i, 0, h) {
		cin >> s[i];
	}
	const int MOD = 998244353;
	ll res = 1;
	rep(i, 0, w + h - 1) {
		// printf("for sum: %d:\n", i);
		int r1 = i < h ? i : h - 1;
		int c1 = i - r1;
		bool has_dot = false, has_r = false, has_b = false;
		rep(j, 0, min(r1 + 1, w - c1)) {
			int nr1 = r1 - j;
			int nc1 = c1 + j;
			// printf("checking: %d, %d\n", nr1, nc1);
			if (s[nr1][nc1] == 'R') {
				has_r = true;
			} else if (s[nr1][nc1] == 'B') {
				has_b = true;
			} else {
				has_dot = true;
			}
		}
		if (has_r && has_b) {
			cout << 0 << endl;
			return 0;
		}
		if (!has_r && !has_b) {
			res = (res * 2) % MOD;
		}
	}
	cout << res << endl;
}