/**
*    author:  Dooloper
*    created: 26.10.2020 13:52:11
**/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i<n;i++)
typedef pair<int,int> P;
#define Mod 998244353

int main() {
   ll h,w,ans=1;
   cin >> h >> w;
   vector <vector <char>> s(h,vector <char>(w));

   rep(i,h){
     rep(j,w){
       cin >> s.at(i).at(j);
     }
   }

   rep(i,h+w){
       ll j=(i<h?i:h-1),k=i-j,co=0;
       char tmp='o';
     //cout << j << k << endl;
       while(j>=0 && k<w){
         //cout <<i<< j << k << endl;
           if((tmp=='R' && s.at(j).at(k)=='B') || (tmp=='B' && s.at(j).at(k)=='R')){
               cout << 0 << endl;
               return 0;
           }
           //cout << 222 << endl;
         //cout << j << k << endl;
            if(s.at(j).at(k)=='.'){
            co++;
            }else if(s.at(j).at(k)=='R'){
            tmp='R';
            }else {
            tmp='B';
            }
           j--;
           k++;
         //cout << 333 << endl;
       }

       if(co!=0 && tmp=='o')
       ans=(ans*2)%Mod;
  


   }
  cout << ans << endl;





}
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
using namespace std;
int main(void){
	int h,w,i,j;
	long long ans = 1,mod=998244353;
	vector<vector<int>> board;
	cin >> h >> w;
	board.assign(h, vector<int>(w,0));
	for(i=0;i<h;i++) {
		string s;
		cin >> s;
		for(j=0;j<w;j++) {
			if(s[j] == 'R') board[i][j] = 1;
			else if (s[j] == 'B') board[i][j] = 2;
			else board[i][j] = 0;
		}
	}
	for(i=0;i<h+w-1;i++) {
		//long long tmp=0;
		int color = 0;
		//bool isupdate = false;
		for(j=0;j<=i;j++) {
			if(i-j >= w) continue;
			if(j >= h) break;
//cout << j << " " << i-j << endl;
			if(board[j][i-j]>0){
				if(color==0) {
					color = board[j][i-j];
				} else {
					if(color != board[j][i-j]){
						color = -1;
						break;
					}
				}
			}
		}
		if(color == -1){
			ans = 0;
			break;
		}
		if(color==0){
			ans *= 2;
			ans %= mod;
		}
	}
	cout << ans << '\n';
}
