#include "bits/stdc++.h"
using namespace std;
 
#define ffor(n) for(int i = 0; i < n; i++)
#define fffor(n) for(int j = 0; j < n; j++)
#define uwu ios::sync_with_stdio(false);cin.tie(NULL);
#pragma GCC optimize("Ofast")
 
const int INF = 1e9 + 7;
const long long INF2 = 1e17;

int main(void) {
	uwu
	
	int n, m; cin >> n >> m;
	vector <string> v(n); 
	ffor(n) cin >> v[i];
	
	const int mod = 998244353;
	long long ans = 1;
	
	for(int i = 0, j = 0; i != n - 1 || j != m - 1; ) {
		set <char> colours;
		for(int x = i, y = j; 0 <= x && x < n && 0 <= y && y < m; x++, y--) {
			if (v[x][y] != '.') colours.insert(v[x][y]);
		}
		if ((int)colours.size() == 0) {
			ans *= 2;
			ans %= mod;
		}
		else if ((int)colours.size() == 1) {
		}
		else if ((int)colours.size() == 2) {
			cout << 0 << '\n';
			return 0;
		}
		
		if (j == m - 1) i++;
		else j++;
	}
	if (v[n - 1][m - 1] == '.') ans *= 2;
	ans %= mod;
	cout << ans << '\n';
}

/*
C:\Users\kenne\OneDrive\Desktop\competitive_programming\main.cpp
*/

#include <iostream>
#include <algorithm>
#include <stack>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <queue>
#include <map>
#define ll long long
using namespace std;
ll n,inx,m,mod=10007,b[200005],a[20005][5],ma[200005];
char s[505][505];

int main()
{
   ios::sync_with_stdio(false);
   cin>>n>>m;
   for(int i=1;i<=n;i++)
   {
       for(int j=1;j<=m;j++)
       {
           cin>>s[i][j];
       }
   }
   int flag=0;
   for(int i=1;i<=n;i++)
   {
       for(int j=1;j<=m;j++)
       {
           if(s[i][j]=='R')
           {
               if(a[i+j][2]==0)
               {
                   a[i+j][1]=1;
               }
               else
               {
                   cout<<0<<endl;
                   return 0;
               }
           }
           if(s[i][j]=='B')
           {
               if(a[i+j][1]==0)
               {
                   a[i+j][2]++;
               }
               else
               {
                    cout<<0<<endl;
                   return 0;
               }
           }
           if(s[i][j]=='.')
           {
               flag=1;
               a[i+j][3]=666;
           }
       }
   }
   ll ans=0;
   for(int i=2;i<=n+m;i++)
   {
       if(a[i][3]==666&&a[i][1]==0&&a[i][2]==0)ans++;
   }
   if(flag==0)cout<<1<<endl;
   else
   {
       ll temp1=1;
       ll temp2=2;
       while(ans)
       {
           if(ans&1)temp1=(temp1*temp2)%998244353;
           temp2=(temp2*temp2)%998244353;
           ans/=2;
       }
       cout<<temp1<<endl;
   }





    return 0;
}
