#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 998244353
#define pii pair<ll,ll>
#define inf 1000000000000000000
#define bpc(x) __builtin_popcountll(x)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define autoitr(x,it) for(auto it = x.rbegin(); it != x.rend(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)
#define hmap gp_hash_table<ll, ll>

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

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

using namespace std;
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());

ll powa(ll a, ll b, ll c)
{
    a%=c;
    if(a<0)
	a+=c;
    ll res = 1;
    while(b>0)
    {
        if(b&1)
            res*=a, res%=c;
        a*=a, a%=c;
        b>>=1;
    }
    return res;
}

int main()
{
  FAST/**/
  
  ll n,m;
  cin>>n>>m;
  
  string arr[n];
  rep(n)
        cin>>arr[i];
  map<ll,map<char,ll>> ma;
  rep(n)
        repi(j,m)
            ma[i+j][arr[i][j]]++;
  ll ans = 1;
  autoit(ma,it)
  {
      map<char,ll> &m = it->ss;
      ll cr = m['R'];
      ll cb = m['B'];
      ll un = m['.'];
      //cout<<"on "<<it->ff<<" "<<cr<<" "<<cb<<" "<<un<<'\n';
      if(cr>0 && cb>0)
      {
          cout<<0<<"\n";
          return 0;
      }
      
      if(cr == 0 && cb == 0)
      {
          //cout<<"at "<<it->ff<<"\n";
          ans *= 2;
          ans%=mod;
          continue;
      }
  }
  cout<<ans<<"\n";
    
  return 0;
}
   
   
 
#include <bits/stdc++.h>
#define endl '\n'
#define INF 0x3f3f3f3f
#define Inf 1000000000000000000LL
#define int long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
using namespace std;
typedef pair<int,int>pii;
int n,m;
char a[510][510];
int cntr,cntb;
signed main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++)cin>>(a[i]+1);
	for(int i=1;i<=m;i++){
		bool flgr=0,flgb=0;
		for(int x=1,y=i;x<=n&&y>=1;x++,y--){
			if(a[x][y]=='R')flgr=1;
			if(a[x][y]=='B')flgb=1;
		}
		if(flgr==1&&flgb==1)return puts("0"),0;
		if(flgr==1)cntr++;
		if(flgb==1)cntb++;
	}
	for(int i=2;i<=n;i++){
		bool flgr=0,flgb=0;
		for(int x=i,y=m;x<=n&&y>=1;x++,y--){
			if(a[x][y]=='R')flgr=1;
			if(a[x][y]=='B')flgb=1;
		}
		if(flgr==1&&flgb==1)return puts("0"),0;
		if(flgr==1)cntr++;
		if(flgb==1)cntb++;
	}
	int t=n+m-1LL-cntr-cntb;
//	cout<<t<<endl;
	int ans=1LL;
	for(int i=1;i<=t;i++)ans=ans*2LL%998244353LL;
	cout<<ans<<endl;
	return 0;
}
/*
rrb
rbr
brr



r.r
.br
...



#####
#####
#####
*/
