#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mod 998244353
#define F first
#define S second
#define all(v) (v).begin(),(v).end()
#define np next_permutation
#define lp(i,n) for(int i=0;i<n;i++)
#define lps(i,j,n) for(int i=j;i<n;i++)
#define vii vector<vi>
#define vb vector<bool>
#define pr pair<int,int>
#define vl vector<ll>
#define vs vector<string>
#define us unordered_map<int,int>
#define Mpq priority_queue<int>
#define mpq priority_queue<int,vi,greater<int>> 
#define eb emplace_back
#define pr pair<int,int>
#define prl pair<ll,ll>
#define vp vector<pr>
#define vpl vector<prl>
#define mkp make_pair
#define ld long double
#define vii vector<vi>
#define Max(a,b) a=max(a,b)
#define Min(a,b) a=min(a,b)
#define ull unsigned long long
#define prr pair<ll,int>
#include <algorithm>
#include <array>
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <vector>
using namespace std;
using vi=vector<int>;
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;

// #include <ext/pb_ds/tree_policy.hpp> 
// #include <ext/pb_ds/assoc_container.hpp>

// using namespace __gnu_pbds;


// typedef  tree<prl, null_type,less<prl>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// ordered_set s;

#define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define EACH(x, a) for (auto& x: a)
template<class T> using pqg = priority_queue<T,vector<T>,greater<T>>;

double epsilon=(double)1e-9;
const int N=(int)2e5+12;
int t;

const ll MX=(ll)1e18+123;
const int inf=0x3fffffff;

map<pr,int> processed;

int fpow(int b){
   int a=2,res=1;
   while(b>0){
      if(b&1) res=(res*1LL*a)%mod;
      a=(a*1LL*a)%mod;
      b>>=1;
   }
   return res;
}

void solve(){
   int h,w,x,cnt=0;
   string s;
   bool ispos=1;
   cin>>h>>w;
   char a[h][w];
   ll ans=0;

   lp(i,h){
      cin>>s;
      lp(j,w) a[i][j]=s[j];
   }

   int l=0,r=0;
   while(r<w){
      int x=l,y=r,c=0,rs=0,bs=0,ds=0;
      while(x<h and y>=0){
         if(a[x][y]=='B') bs++;
         else if(a[x][y]=='R') rs++;
         else ds++;
         x++,y--;
         c++;
      }
      if(bs>0 and rs>0) {
         ispos=0;
         break;
      }
      if(ds==c) cnt++;
      r++;
   }

   l=1,r=w-1;
   while(l<h){
      int x=l,y=r,c=0,rs=0,bs=0,ds=0;
      while(x<h and y>=0){
         if(a[x][y]=='B') bs++;
         else if(a[x][y]=='R') rs++;
         else ds++;
         x++,y--;
         c++;
      }
      if(bs>0 and rs>0){
         ispos=0;
         break;
      }
      if(ds==c) cnt++;
      l++;
   }
   if(!ispos){
      cout << 0 << endl;
      return;
   }
   cout << fpow(cnt) << endl; 
}

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

   solve();
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 998244353;
using P=pair<ll,ll>;
const ll inf = 1ll<<60;
int main() {
    ll h,w;
    cin >> h >> w;
    vector<vector<char>>mp(h,vector<char>(w));
    for(ll i=0;i<h;i++){
        for(ll j=0;j<w;j++) cin >> mp[i][j];
    }
    vector<ll>data(h+w,0);
    for(ll i=0;i<h+w;i++){
        bool blue=false,red=false,dot=false;
        for(ll j=0;j<=i;j++){
            if(j>=h||(i-j)>=w) continue;
            if(mp[j][i-j]=='R') {
                red=true;
            }
            if(mp[j][i-j]=='B'){
                blue=true;
            }
            if(mp[j][i-j]=='.'){
                dot=true;
            }
        }
        if(blue&&red) data[i]=0;
        else if(!dot) data[i]=1;
        else if(red||blue) data[i]=1;
        else if(dot)data[i]=2;
    }
    ll ans=1;
    for(ll i=0;i<h+w;i++){
        ans*=data[i];
        ans%=MOD;
    }
    cout << ans << endl;
}
