
/*
	*	Created By: 'Present_Sir'
	*	Created On: Thursday 27 May 2021 10:33:10 AM
*/

#include<bits/stdc++.h>
#define int long long
using namespace std;

const int Mod = 998244353;
template <int mod>
struct ModInt {
    int x;
    ModInt() : x(0) {}
    ModInt(long long x_) {
        if ((x = x_ % mod + mod) >= mod) x -= mod;
    }
    ModInt& operator+=(ModInt rhs) {
        if ((x += rhs.x) >= mod) x -= mod;
        return *this;
    }
    ModInt& operator-=(ModInt rhs) {
        if ((x -= rhs.x) < 0) x += mod;
        return *this;
    }
    ModInt& operator*=(ModInt rhs) {
        x = (unsigned long long)x * rhs.x % mod;
        return *this;
    }
    ModInt& operator/=(ModInt rhs) {
        x = (unsigned long long)x * rhs.inv().x % mod;
        return *this;
    }

    ModInt operator-() const { return -x < 0 ? mod - x : -x; }
    ModInt operator+(ModInt rhs) const { return ModInt(*this) += rhs; }
    ModInt operator-(ModInt rhs) const { return ModInt(*this) -= rhs; }
    ModInt operator*(ModInt rhs) const { return ModInt(*this) *= rhs; }
    ModInt operator/(ModInt rhs) const { return ModInt(*this) /= rhs; }
    bool operator==(ModInt rhs) const { return x == rhs.x; }
    bool operator!=(ModInt rhs) const { return x != rhs.x; }
    ModInt inv() const { return pow(*this, mod - 2); }
    
    friend ostream& operator<<(ostream& s, ModInt<mod> a){ s << a.x; return s; }
    friend istream& operator>>(istream& s, ModInt<mod>& a){ s >> a.x; return s; }
};

using mint = ModInt<Mod>;

// ...
// ...
// ...
// ...

int32_t main(){
 
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
   

    int n, m;
    cin >> n >> m;

    vector < string > s(n);
    for(auto &x: s) cin >> x;

    mint ans = 1;

    for(int i=0; i<n+m-1; ++i){
        int a=0, b=0, cnt=0;
        int nx = 0;
        for(int j=i; j>=0; --j){
            int ny = j;
            if(nx>=0 and ny>=0 and nx<n and ny<m){
                if(s[nx][ny] == 'R')++a;
                if(s[nx][ny]=='B')++b;
                if(s[nx][ny]=='.')++cnt;
            }
            ++nx;
        }
        //cerr <<  a << " " << b << "\n";
        if(a>0 and b>0){
            cout << 0 << "\n";
            return 0;
        }else if(a == 0 and b == 0){
            ans *= 2;
        }
    }

    cout << ans << "\n";

    return 0;
}

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0; i<(n); i++)
#define sz(x) int(x.size())

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    int h,w; cin >> h >> w;
    vector<string> s(h);
    rep(i,h) cin >> s[i];

    vector<bool> flag_R(h+w-1);
    vector<bool> flag_B(h+w-1);

    rep(i,h)rep(j,w){
        if(s[i][j] == 'R') flag_R[i+j] = true;
        if(s[i][j] == 'B') flag_B[i+j] = true;
    }

    ll ans = 1;
    rep(i,h+w-1){
        if(flag_R[i] && flag_B[i]){
            ans = 0;
        }
        if(!flag_R[i] && !flag_B[i]){
            ans *= 2; ans %= 998244353;
        }
    }
    cout << ans << endl;

    return 0;
}
