#include <bits/stdc++.h>

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
 
// using namespace __gnu_pbds;

using namespace std;
#define M                    998244353
#define pi                   3.14159265358979323846
#define ll                   long long
#define lld                  long double

// Pair
#define pii                  pair<int, int>
#define pll                  pair<ll, ll>

// Vector
#define vl                   vector<ll >
#define vi                   vector<int>
#define vpi                  vector<pii>
#define vpl                  vector<pll>
#define pb                   push_back
#define mp                   make_pair


// Search
#define lb                   lower_bound
#define ub                   upper_bound
#define mina                 *min_element
#define mama                 *max_element
#define bsrch                binary_search

////////
#define F                    first
#define S                    second
#define cel(x,a)             ((x + a - 1) / a)
#define all(v)               v.begin(), v.end()
#define allrev(v)            v.rbegin(), v.rend()
#define lcm(m, n)            ((m / __gcd(m, n))*n)
#define deb(...)             cerr << "(" << #__VA_ARGS__ << "):", dbg(__VA_ARGS__)
#define ms(arr, v)           memset(arr, v, sizeof(arr))
#define ps(x,y)              fixed << setprecision(y) << x
#define _X_                  ios_base::sync_with_stdio(false); cin.tie(NULL)

//pbds
#define ordered                 tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

// Input / Output
#define scn(str)             scanf("%s", str)
#define pri(str)             printf("%s\n", str)


const int N = 5e5 + 4;

inline void  dbg()           { cerr << endl; }


template <typename T, typename... V>
inline void  dbg(T t, V... v) {cerr << ' ' << t; dbg(v...);}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

ll binpow(ll a,ll b,ll p){
    if(b==0)return 1;
    ll t=binpow(a,b/2,p);
    if(b%2)return (((a*t)%p)*t)%p;
    else return ((t*t)%p);
}
 

void solve()
{
    int h,w;
    cin >> h >> w;
    string s[h];
    for(int i = 0; i<h; i++)cin >> s[i];
    bool val[h+w-1] = {0};
    for(int i = 0; i<h; i++)
    {
		for(int j = 0; j<w; j++)
		{
			if(s[i][j]=='R')
			{
				val[i+j] = 1;
			}
		}
	}
	bool val2[h+w-1] = {0};
	for(int i = 0; i<h; i++)
    {
		for(int j = 0; j<w; j++)
		{
			if(s[i][j]=='B')
			{
				val2[i+j] = 1;
			}
		}
	}
	int cnt = 0;
	for(int i = 0; i<h+w-1; i++)
	{
		if(val[i] && val2[i])
		{
			cout << "0\n";
			return;
		}else if(!val[i] && !val2[i])cnt++;
	}
	ll ans = binpow(2,cnt,M);
	cout << ans << "\n";
}


int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
    // clock_t time_req = clock();
    int t = 1;
     //cin>> t;
    while (t--) {
       solve();



   }


    // time_req = clock() - time_req;
    // cout << (float)time_req / CLOCKS_PER_SEC;
   return 0;
}

#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pair<int,int>>
#define vpll vector<pair<ll,ll>>
#define fr(i,k,n) for (int i = k; i < n; ++i)
#define fri(i,k,n) for (int i = k; i >= n; --i)
#define pb push_back
#define mp make_pair
#define all(arr) arr.begin(),arr.end()
#define ff first
#define ss second

const double pi=3.1415926535897932384626433832795;
const int inf=1e9;
const ll inf2=1e18;
const int mod=998244353;

void boost(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

void solve(){
    int h,w;
    cin>>h>>w;
    string s[h];
    fr(i,0,h){
        cin>>s[i];
    }
    vi adj[h-1+w];
    fr(i,0,h){
        fr(j,0,w){
            if(s[i][j]=='.'){
                continue;
            }
            else if(s[i][j]=='R'){
                adj[i+j].pb(1);
            }
            else{
                adj[i+j].pb(2);
            }
        }
    }
    ll ans=1;
    for(int i=0;i<=(h-1+w-1);i++){
        int v=0;
        for(auto x: adj[i]){
            v|=x;
        }
        // cout<<i<<endl;
        if(v==3){
            cout<<0<<endl;
            return;
        }
        else if(v==0){
            ans=(ans*2LL)%mod;
        }
    }
    cout<<ans<<endl;
    return;
}

int main()
{
    boost();
    
    int tc=1;
    //cin>>tc;
    while(tc--)
        solve();
    return 0;
}