#include<bits/stdc++.h>
using namespace std;
char s[520][520];
int r[1020],b[1020];
int main()
{
	int n,m;
	cin>>n>>m;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			cin>>s[i][j];
		}
	}
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			if(s[i][j]=='R')
			{
				r[i+j]=1;
			}
			if(s[i][j]=='B')
			{
				b[i+j]=1;
			}
		}
	}
	int z=1;
	for(int i=0;i<n+m-1;i++)
	{
		z=z*(2-r[i]-b[i])%998244353;
	}
	cout<<z;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
const int N=2e3+5;
const int M=65;
const int inf=1e9;
const int mod=998244353;;
const double eps=1e-8;
const long double pi=acos(-1.0L);
#define ls (i<<1)
#define rs (i<<1|1)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define mem(a,b) memset(a,b,sizeof(a))
LL read()
{
    LL x=0,t=1;
    char ch;
    while((ch=getchar())<'0'||ch>'9') if(ch=='-') t=-1;
    while(ch>='0'&&ch<='9'){ x=(x<<3)+(x<<1)+ch-'0'; ch=getchar(); }
    return x*t;
}

char s[N][N];
vector<char> e[N<<1];
int n,m,vis[N][N];
void dfs(int x,int y,int step)
{
    vis[x][y]=1;
    e[step].eb(s[x][y]);
    if(x<n&&!vis[x+1][y]) dfs(x+1,y,step+1);
    if(y<m&&!vis[x][y+1]) dfs(x,y+1,step+1);
}
int main()
{
    n=read(),m=read();
    for(int i=1;i<=n;i++) scanf("%s",s[i]+1);
    dfs(1,1,1);
    int flag=1;
    LL ans=1;
    for(int i=1;i<=n+m-1;i++)
    {
        int t1=0,t2=0;
        for(auto x:e[i])
            if(x=='R') t1++;
            else if(x=='B') t2++;
        if(t1&&t2) flag=0;
        if(!flag) break;
        if(t1==0&&t2==0) ans=ans*2%mod;
    }
    if(!flag) printf("0\n");
    else printf("%lld\n",ans);
    return 0;
}
/*
4
4
0 1
0 2
2 3
2
1 0
4
0 1
0 2
2 3
2
1 0
*/
