#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define deb(...)
#endif
#define endl "\n"
#define pb push_back
#define int long long
#define ll long long
#define pii pair<int,int>
#define F first
#define S second
#define all(c) c.begin(),c.end()
#define read(v) for(auto &it:v) cin>>it;
const int inf = 1e18;
const int N   = 2e5 + 5;
const int mod = 998244353;
int n, m;
char A[505][505];

int madd(int a, int b)
{
    return (a + b) % mod;
}
int msub(int a, int b)
{
    return (((a - b) % mod) + mod) % mod;
}
int mmul(int a, int b)
{
    return ((a % mod) * (b % mod)) % mod;
}
int mpow(int base, int exp)
{
    int res = 1;
    while (exp)
    {
        if (exp % 2 == 1)
        {
            res = (res * base) % mod;
        }
        exp >>= 1;
        base = (base * base) % mod;
    }
    return res;
}
int minv(int base)
{
    return mpow(base, mod - 2);
}
int mdiv(int a, int b)
{
    return mmul(a, minv(b));
}
void testCase() {
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            cin >> A[i][j];
        }
    }
    map <int, multiset <char>> mpp;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            mpp[i + j].insert(A[i][j]);
        }
    }
    int ans = 1;
    for (int i = 2; i <= n + m; i++) {
        if (mpp[i].find('R') != mpp[i].end() && mpp[i].find('B') != mpp[i].end()) {
            cout << 0 << endl;
            return;
        }
        else {
            if (mpp[i].find('.') != mpp[i].end()) {
                if ((mpp[i].find('R') != mpp[i].end()) || (mpp[i].find('B') != mpp[i].end())) {
                    continue;
                }
                else {
                    ans = mmul(ans, 2);
                }

            }
        }
    }
    cout << ans << endl;


}

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int  t = 1;
    // cin >> t;
    while (t--)testCase();
    return 0;
}
#include<bits/stdc++.h>
using namespace std;
const int N=505,p=998244353;
char s[N][N];
int n,m;
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	scanf("%s",s[i]+1);
	int cnt=0;
	for(int i=1;i<=n;i++)
	for(int j=1;j<=m;j++)
		if(i-1&&j+1<=m)
		{
			if(s[i][j]!='.'&&s[i-1][j+1]!='.'&&s[i][j]!=s[i-1][j+1])
			{
			//	cout<<s[i][j]<<endl;
				cnt=-1;
				break;
			}
		}
	if(cnt==-1)
	{
		cout<<"0";
		return 0;
	}
	cnt=1;
	for(int i=2;i<=n+m;i++)
	{
		int fl=1;
		for(int j=1;j<=i-1;j++)
		{
			 if(i-j&&i-j<=n&&j<=m&&s[i-j][j]!='.')
		{
			fl=0;
			break;
		}
		}
		
		if(fl) cnt=cnt*2%p;
	}
	cout<<cnt;
	return 0;
}