//g++  7.4.0

#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 998244353

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll N,M; cin>>N>>M;
    string s[N];
    ll ans = 1;
    
    for(ll i=0;i<N;++i)
        cin>>s[i];
    
    for(ll j=0;j<M;++j)
    {
        ll i = 0;
        ll jj = j;
        ll tot_R = 0;
        ll tot_B = 0;
        while(i >= 0 && jj >= 0 && i < N && jj < M)
        {
            //cout<<i<<" "<<jj<<endl;
            if(s[i][jj] == 'R')
                tot_R++;
            else if(s[i][jj] == 'B')
                tot_B++;
            --jj;
            ++i;
            
            
        }
        
        //cout<<"----------"<<endl;
        
        if(tot_R != 0 && tot_B != 0)
        {
            cout<<0<<endl;
            return(0);
        }
        
        if(!tot_R && !tot_B)
            ans *= 2LL;
        
        ans %= MOD;
    }
    
    for(ll i=1;i<N;++i)
    {
        ll ii = i;
        ll j = M - 1;
        ll tot_R = 0;
        ll tot_B = 0;
        while(j >= 0 && ii >= 0 && j < M && ii < N)
        {

            if(s[ii][j] == 'R')
                tot_R++;
            else if(s[ii][j] == 'B')
                tot_B++;
                
            j--;
            ii++;
        }
        
        if(tot_R != 0 && tot_B != 0)
        {
            cout<<0<<endl;
            return(0);
        }
        
        if(!tot_R && !tot_B)
            ans *= 2LL;
        
        ans %= MOD;
    }
    
    cout<<ans<<endl;
}
//#include <bits/stdc++.h>
//using namespace std;
#include <cstdio>

#define rep(i,_l,_r) for(signed i=(_l),_end=(_r);i<=_end;++i)
#define fep(i,_l,_r) for(signed i=(_l),_end=(_r);i>=_end;--i)
#define erep(i,u) for(signed i=head[u],v=to[i];i;i=nxt[i],v=to[i])
#define efep(i,u) for(signed i=Head[u],v=to[i];i;i=nxt[i],v=to[i])
#define print(x,y) write(x),putchar(y) 
//#define debug(...) do {cerr<<__LINE__<<" : ("#__VA_ARGS__<<") = "; Out(__VA_ARGS__); cerr<<flush;} while(0)
//template <typename T> void Out(T x) {cerr<<x<<"\n";}
//template <typename T,typename ...I> void Out(T x,I ...NEXT) {cerr<<x<<", "; Out(NEXT...);}

template <class T> inline T read(const T sample) {
    T x=0; int f=1; char s;
    while((s=getchar())>'9'||s<'0') if(s=='-') f=-1;
    while(s>='0'&&s<='9') x=(x<<1)+(x<<3)+(s^48),s=getchar();
    return x*f;
}
template <class T> inline void write(const T x) {
    if(x<0) return (void) (putchar('-'),write(-x));
    if(x>9) write(x/10);
    putchar(x%10^48);
}
template <class T> inline T Max(const T x,const T y) {if(x>y) return x; return y;}
template <class T> inline T Min(const T x,const T y) {if(x<y) return x; return y;}
template <class T> inline T fab(const T x) {return x>0?x:-x;}
template <class T> inline T gcd(const T x,const T y) {return y?gcd(y,x%y):x;}
template <class T> inline T lcm(const T x,const T y) {return x/gcd(x,y)*y;}
template <class T> inline T Swap(T &x,T &y) {x^=y^=x^=y;}

#define int long long

const int mod=998244353;

int n,m,be[100000];
char s[1000][1005];

int qkpow(int x,int y) {
	int r=1;
	rep(i,1,y) r=1ll*r*2%mod;
	return r;
}

signed main() {
	n=read(9),m=read(9);
	rep(i,1,n) scanf("%s",s[i]+1);
	rep(i,1,n) rep(j,1,m) {
		int d=0;
		if(s[i][j]=='R') d=1;
		else if(s[i][j]=='B') d=2; 
		//int d=(s[i][j]=='R'?1:(s[i][j]=='B'?2:0));
		if(be[i+j]==0) be[i+j]=d;
		else if(d && (be[i+j]^d)) return puts("0"),0;
	}
	int ans=0;
	rep(i,2,n+m) ans+=(be[i]==0);
	print(qkpow(2,ans),'\n');
	return 0;
}