#include <bits/stdc++.h>
#define MOD 998244353LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int h,w;
int fie[501][501];
int flag[1001];

int main(void){
	scanf("%d%d",&h,&w);
	for(int i=0;i<h;i++){
		string s;
		cin >> s;
		for(int j=0;j<w;j++){
			if(s[j]=='R'){
				fie[i][j]=1;
			}else if(s[j]=='B'){
				fie[i][j]=2;
			}else{
				fie[i][j]=0;
			}
		}
	}
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			flag[i+j]|=(1<<fie[i][j]);
		}
	}
	ll ans=1;
	for(int i=0;i<h+w-1;i++){
		if(flag[i]&2 && flag[i]&4){
			ans=0;
		}else{
			if(flag[i]&1){
				if((flag[i]&2)==0 && (flag[i]&4)==0){
					ans=ans*2%MOD;
				}
			}
		}
	}
	printf("%lld\n",ans);
	return 0;
}

/*input

*/
#include <bits/stdc++.h>
#define up(i,a,b) for(int (i) = (a);(i)<=(b);++(i))
#define down(i,b,a) for(int (i) = (b);i>=(a);--i)
#define bits(x,i) (((x) >> (i)) & 1)
#define mid ((l+r)/2)
#define pr pair<int,int>
using namespace std;
const int N = 1005;
int a[N], n;
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    up(i,1,n) cin >> a[i];
    int ans = 0;
    up(i,1,n) ans += a[i] - min(a[i], 10);
    cout << ans;
}