


#include  <iostream>
#include  <stdio.h>
#include <algorithm>
#include <map>
#include <math.h>
#include <queue>
#include <vector>
#include <stack>
#include <set>
#include <bitset>

using namespace std;
#define rep(i,n) for (ll i = 0; i < (n) ; i++)
#define rep2(i,n,i2,n2) for (ll i = 0; i < (n) ; i++) for (ll i2 = 0; i2 < (n2) ; i2++)
#define incRepFT(i,s,n) for (ll i = (s); i <= (n) ; i++)
#define decRepFT(i,s,n) for (ll i = (s); i >= (n) ; i--)

#define INF 1e9
#define llINF 1e18
#define base10_4 10000      //1e4
#define base10_5 100000     //1e5
#define base10_6 1000000    //1e6
#define base10_7 10000000   //1e7
#define base10_8 100000000  //1e8
#define base10_9 1000000000 //1e9

#define MOD 998244353
#define pb push_back
#define ll long long
#define ld long double
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>
#define vvll vector<vector<ll>>
#define vstr vector<string>
#define vvstr vector<vector<string>>
typedef pair<ll,ll> P;  




// #include <iomanip>
//  cout << fixed << setprecision(15) << y << endl;

// for(char c : S)

//min({a1, a2, ..., an})
//max({a1, a2, ..., an})
//swap(a, b)
//S.substr(si)
// sort <--> reverse
//count(v.begin(), v.end(), x) 
// char t - 'a'
// char t - '0'

//xを2進数にした時の1の数
//__builtin_popcount(x) 
//__builtin_popcountll(x) 

ll A;
ll B;
ll C;
ll D;
ll N;
ll M;
ll K;
ll T;
ll H;
ll W;
ll X;
ll Y;
ll Z;

string S;
vstr Ss;

ll ltmp;
string stmp;
double dtmp;

ll llmin(ll a,ll b){
    if(a>=b) return b;
    return a;
}
ll llmax(ll a,ll b){
    if(a<=b) return b;
    return a;
}
P d_move[4] = {
    P(0 , 1),P(0 , -1),P(1 , 0),P(-1 , 0)//,P(1 , 1),P(1 , -1),P(-1 , 1),P(-1 , -1)
};
//for(P drc : d_move)

double double_hosei = 1000000; //求められる精度分補正をかけておく
map<char,ll> mapcnt[1010]; 
ll getPower(ll value,ll shisu,ll mod){
    ll ans = 1;
    ll cnt = shisu;
    while(cnt>0){
        if(cnt%2==1){
            ans = ans * value % mod;
        }
        value = value * value % mod;
        cnt = cnt/2;
    }
    return ans;
}
ll getans(){
    ll sentaku = 0;
    ll maxsum = (H-1) + (W-1);
    //cout << "start" << endl;
    for( ll si = 0 ; si <=maxsum ; si++ ){
        map<char,ll> mapcnt;
        ll hi_start = llmax(0,si-(W-1));
        for( ll hi = 0 ; hi <H ; hi++ ){
            ll wi = si - hi;
            if(wi < 0 ) break;
            if(wi > W-1) continue;
            //cout << si << " " << hi << " " << wi << endl;
            mapcnt[ Ss[hi][wi] ]++;
        }
        if(mapcnt['R']>0 && mapcnt['B']>0) return 0;
        else{
            if(mapcnt['R']==0 && mapcnt['B']==0) sentaku++;
        }
    }
    ll ans = getPower(2,sentaku,MOD);
    return ans;
    
}
int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin >> H;
    cin >> W;

    Ss.resize(H);
    rep(hi,H) cin >> Ss[hi];
    cout << getans() << endl;


}
#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;
}