#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
const double pi=3.1415926535897932384626;
inline ll read(){
	ll x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-') f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
	}
	return x*f;
}
const ll mod=998244353;
const int maxn=5e2+5;
ll n,m;
char s[maxn][maxn];
ll q_pow(ll x,ll y){
    ll ans=1;
    while(y){
        if(y&1) ans=ans*x%mod;
        y>>=1;
        x=x*x%mod;
    }
    return ans;
}
int main(){
    n=read(),m=read();
    for(int i=1;i<=n;++i) scanf("%s",s[i]+1);
    ll cnt=0,flag=1;
    for(int i=1;i<=n;++i){
        int x=i,y=1,r=0,b=0,tmp=0;
        while(x>=1&&y<=m){
            if(s[x][y]=='.') ++tmp;
            else if(s[x][y]=='R') r=1;
            else b=1;
            --x;
            ++y;
        }
        if(r==1&&b==1) flag=0;
        else if(r+b==0&&tmp) ++cnt;
    }
    for(int i=2;i<=m;++i){
        int x=n,y=i,r=0,b=0,tmp=0;
        while(x>=1&&y<=m){
            if(s[x][y]=='.') ++tmp;
            else if(s[x][y]=='R') r=1;
            else b=1;
            --x;
            ++y;
        }
        if(r==1&&b==1) flag=0;
        else if(r+b==0&&tmp) ++cnt;
    }
    if(!flag) printf("0\n");
    else printf("%lld\n",q_pow(2,cnt));
    return 0;
}

#include <bits/stdc++.h>
#define DEBUG if(0)
#define lli long long int
#define ldouble long double
using namespace std;

const int maxX = 72, maxPrimes = 20;
bool notPrime[maxX + 1];
vector<lli> primes;

const int maxN = 72;
lli a, b; int n;
int primesMask[maxN + 1];
lli memo[maxN + 1][1LL << maxPrimes];
lli solve(int i = 0, int mask = 0)
{
  if (i == n + 1)
    return 1;
  lli &ans = memo[i][mask];
  if (ans != -1)
    return ans;

  ans = solve(i + 1, mask);
  if (!(mask & primesMask[i]))
    ans += solve(i + 1, mask | primesMask[i]);
  return ans;
}

int main()
{
  notPrime[0] = notPrime[1] = true;
  for (int i = 2; i <= maxX; i ++)
  {
    if (!notPrime[i]) primes.push_back(i);
    for (int j = 0; i*primes[j] <= maxX; j ++)
    {
      notPrime[i*primes[j]] = true;
      if (i % primes[j] == 0) break;
    }
  }

  while (~scanf("%lld %lld", &a, &b))
  {
    n = b - a;
    for (lli i = a; i <= b; i++)
    {
      primesMask[i - a] = 0;
      for (int j = 0; j < primes.size(); j++)
      {
        int p = primes[j];
        if (i % p == 0)
          primesMask[i - a] |= (1LL << j);
      }
    }

    memset(memo, -1, sizeof(memo));
    lli ans = solve();
    printf("%lld\n", ans);
  }
  return 0;
}