#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<set>
#include<cstdio>
#include<map>
#include<cassert>

using namespace std;

#define ll long long
#define reps(i, a, b) for(int i = a; i < b; i++)
#define rreps(i, a, b) for(int i = a-1; i >= b; i--)
#define rep(i, n) reps(i, 0, n)
#define rrep(i, n) rreps(i, n, 0)
#define P pair<int, int>
#define vec vector<int>
#define mat vector<vec>

const ll mod = 998244353;
const int INF = 1001001001;

struct mint {
    ll x;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};
istream& operator>>(istream& is, const mint& a){ return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a){ return os << a.x; }

int main(){
    int h, w;
    cin >> h >> w;
    string s[h];
    rep(i, h){
        cin >> s[i];
    }
    mint ans(1);
    rep(i, h){
        set<char> t;
        int x = i;
        int y = 0;
        while(x >= 0 && y < w){
            t.insert(s[x][y]);
            x--;
            y++;
        }
        if(t.size() == 3){
            ans *= 0;
        }else if(t.size() == 2){
            if(t.find('.') == t.end()){
                ans *= 0;
            }else{
                ans *= 1;
            }
        }else{
            if(t.find('.') == t.end()){
                ans *= 1;
            }else{
                ans *= 2;
            }
        }
    }
    reps(i, 1, w){
        set<char> t;
        int x = h-1;
        int y = i;
        while(x >= 0 && y < w){
            t.insert(s[x][y]);
            x--;
            y++;
        }
        if(t.size() == 3){
            ans *= 0;
        }else if(t.size() == 2){
            if(t.find('.') == t.end()){
                ans *= 0;
            }else{
                ans *= 1;
            }
        }else{
            if(t.find('.') == t.end()){
                ans *= 1;
            }else{
                ans *= 2;
            }
        }
    }
    cout << ans << endl;
}
#include<iostream>
#include<algorithm>
#include<cstring>

using namespace std;

const int N = 510, mod = 998244353;

int n, m;
char a[N][N];
int c[2 * N];

int main(){
    scanf("%d%d", &n, &m);
    
    for(int i = 1; i <= n; i ++) scanf("%s", a[i] + 1);
    
    for(int i = 1; i <= n; i ++)
        for(int j = 1; j <= m; j ++)
            if(a[i][j] == 'R') c[i + j] |= 1;
            else if(a[i][j] == 'B') c[i + j] |= 2;
        
    int res = 1;
    for(int i = 2; i <= n + m; i ++)
        if(c[i] == 0) res = 2 * res % mod;
        else if(c[i] == 3) res = 0;
        
    printf("%d\n", res);
    return 0;
}