#pragma GCC optimize("Ofast") 
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define sz(a) (int)(a.size())
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define MOD (ll)(1e9+7)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
typedef pair<int,pii> P;
ll gcd(ll a,ll b){if(!b)return a;else return gcd(b,a%b);}
int main()
{
	int n;
	cin>>n;
	vector<ll>a(n);
	ll ans = INF;
	for(int i=0;i<n;i++)cin>>a[i];
	/*
	for(ll i=0;i<(1<<n);i++){
		ll fin = 0;
		for(int j=0;j<n;j++){
			int k = j;
			ll cur = a[j];
			while(k+1<n){
				int c = i&(1LL<<j);
				int b = i&(1LL<<k);
				if(c && !b)break;
				if(b && !c)break;
				k++;
				cur = cur|a[k];
			}
			fin= cur ^ fin;
			j = k;
		}
		ans = min(ans,fin);
	}*/
	vector<set<ll>>b(20);
	for(int i=0;i<n;i++){
		ll cur = 0;
		for(int j=i;j>=0;j--){
			cur = cur|a[j];
			if(j == 0)b[i].insert(cur);
			else{
				for(ll x:b[j-1]){
					b[i].insert(cur ^ x);
				}
			}
		}
	}
	for(ll x:b[n-1])ans = min(ans,x);
	cout<<ans;
}

#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
#define rep(i, n) for(int i=0;i<n;i++)
#define all(i, v) for(auto& i : v)
typedef long long ll;
using namespace std;
const ll mod=998244353, INF=(1LL<<60);
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;




long long modpow(long long a, long long n) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}


int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll cnt = 0;
    ll h, w;
    cin >> h >> w;
    vector<string> s(h);
    rep(i, h) cin >> s[i];
    bool ng = false;
    for(ll k=0;k<=h+w-2;k++) {
        int num = 0;
        for(ll i=min(k, h-1);i>=max(0LL, k-(w-1));i--) {
            ll j = k - i;
            if(s[i][j] == 'R') {
                if(num == 0) num++;
                else if(num == -1) ng = true;
            }else if(s[i][j] == 'B') {
                if(num == 0) num--;
                else if(num == 1) ng = true;
            }
        }
        if(num == 0) cnt++;
    }
    if(ng) {
        cout << 0 << endl;
        return 0;
    }
    cout << modpow(2LL, cnt) << endl;
    return 0;
}

