#include<bits/stdc++.h>

#define ll long long int
#define ld long double
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x))
#define pii pair<int,int>
#define pll pair<ll,ll>
#define INF 1e9+10
#define INFL 1e18
//#define mod 1000000007
#define mod 998244353

#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
ll power(ll x,ll n){ll res =1;while(n>0){if(n%2==1){res=res*x;}x=x*x;n=n/2;}return res;}
ll powm(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
//cout<< fixed << setprecision(10)
//__builtin_popcountll()
//max no of prime factor 5*1e5=7, 1e6=8, 1e9=10;



int main()
{
    fast;
    int n,m,i,j;
    cin>>n>>m;
    string s[n];
    for(i=0;i<n;i++)
        cin>>s[i];
    ll ans=1;
    ll f[n+m+10][4];
    mem(f,0);
    for(i=0;i<n;i++)
    {
        for(j=0;j<m;j++)
        {
            f[i+j][0]++;
            if(s[i][j]=='R')
                f[i+j][1]++;
            if(s[i][j]=='B')
                f[i+j][2]++;
            if(s[i][j]=='.')
                f[i+j][3]++;



        }
    }
    
    for(i=0;i<n+m-1;i++)
    {
        if(f[i][1]!=0&&f[i][2]!=0)
        {
            cout<<0<<"\n";
            return 0;
        }
        
        if(f[i][0]==f[i][3])
        {
            ans=ans*2;
            ans=ans%mod;
            continue;
        }
        
    }
    cout<<ans<<"\n";


    
}
#include<bits/stdc++.h>
#define rep(i,a,b) for(R int i=a;i<=b;i++)
#define R register
#define endl putchar('\n')
const int N=1005;
const long long mod=998244353;
using namespace std;

int n,m;
long long ans=1;
char s[N][N];

void solve() {
	rep(sm,2,n+m) {
		int r=0,b=0;
		if(sm<=m+1) {
			rep(i,1,sm-1) {
				int j=sm-i;
				r|=s[i][j]=='R';
				b|=s[i][j]=='B';
			}
		} else {
			rep(i,sm-m,n) {
				int j=sm-i;
				r|=s[i][j]=='R';
				b|=s[i][j]=='B';
			}
		}
		if(r&&b) { printf("0"),exit(0); }
		else if(!r&&!b) (ans*=2ll)%=mod;
	}
}

int main() {
	scanf("%d%d",&n,&m);
	rep(i,1,n) scanf("%s",s[i]+1);
	solve();
	printf("%lld",ans);
	return 0;
}