#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
const double pi=3.1415926535897932384626;
inline ll read(){
	ll x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-') f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
	}
	return x*f;
}
const ll mod=998244353;
const int maxn=5e2+5;
ll n,m;
char s[maxn][maxn];
ll q_pow(ll x,ll y){
    ll ans=1;
    while(y){
        if(y&1) ans=ans*x%mod;
        y>>=1;
        x=x*x%mod;
    }
    return ans;
}
int main(){
    n=read(),m=read();
    for(int i=1;i<=n;++i) scanf("%s",s[i]+1);
    ll cnt=0,flag=1;
    for(int i=1;i<=n;++i){
        int x=i,y=1,r=0,b=0,tmp=0;
        while(x>=1&&y<=m){
            if(s[x][y]=='.') ++tmp;
            else if(s[x][y]=='R') r=1;
            else b=1;
            --x;
            ++y;
        }
        if(r==1&&b==1) flag=0;
        else if(r+b==0&&tmp) ++cnt;
    }
    for(int i=2;i<=m;++i){
        int x=n,y=i,r=0,b=0,tmp=0;
        while(x>=1&&y<=m){
            if(s[x][y]=='.') ++tmp;
            else if(s[x][y]=='R') r=1;
            else b=1;
            --x;
            ++y;
        }
        if(r==1&&b==1) flag=0;
        else if(r+b==0&&tmp) ++cnt;
    }
    if(!flag) printf("0\n");
    else printf("%lld\n",q_pow(2,cnt));
    return 0;
}

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

int main(){
  int h, w; cin >> h >> w;
  const int mod = 998244353;
  string tmp;
  vector<vector<char>> grid(h, vector<char>(w));
  for(int i = 0; i < h; ++i){
    cin >> tmp;
    for(int j = 0; j < w; ++j){grid[i][j] = tmp[j];}
  }
  
  vector<vector<int>> state(h+w-1, vector<int>(3)); // ["R", "B", "."]
  for(int i = 0; i < h; ++i){
    for(int j = 0; j < w; ++j){
      if(grid[i][j] == 'R'){state[i+j][0] += 1;}
      if(grid[i][j] == 'B'){state[i+j][1] += 1;}
      if(grid[i][j] == '.'){state[i+j][2] += 1;}
    }
  }  
  
  int ans = 1;
  for(int i = 0; i < h+w-1; ++i){
    if(state[i][0] == 0 && state[i][1] == 0){ans *= 2;}
    if(state[i][0] != 0 && state[i][1] != 0){ans *= 0;}
    ans %= mod;
  }
  cout << ans << endl;  
}