#include <bits/stdc++.h>
#include <chrono>

using namespace std;
using namespace chrono;

typedef long long int ll;
typedef vector<int> vii;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define pb push_back
#define odd(x) ((x)&1)
#define even(x) (!odd(x))
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(auto i=0;i<n;++i)
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define TEST_CASE int tc;cin>>tc;while(tc--)
#define Clock high_resolution_clock::now()

template<class T>
inline bool chmax(T &a, T b) {if(a < b) {a = b;return true;}return false;}
template<class T>
inline bool chmin(T &a, T b) {if(a > b) {a = b;return true;}return false;}

#ifdef LOCAL
#define cerr cout
#else
#endif

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif


void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}


template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
// #define TIME

/******************************************************************************************************************************/


const ll inf = 2e18;
const ll mod = 998244353;
const ll N = 1e5+3;


int main()
{
    auto start_time = Clock;
    FASTIO


    ll n,m;
    cin >> n >> m;
    vector<string> s(n);
    vector<vll> mp(n+m+1);
    rep(i,n) {
        cin >> s[i];
        rep(j,m) {
            ll x = i+j;
            if(s[i][j] == 'R') mp[x].pb(1);
            else if(s[i][j] == 'B') mp[x].pb(-1);
            else mp[x].pb(0);
        }
    }
    ll ans = 1, ok = 1;
    rep(i,n+m+1) {
        ll R,B,D;
        R = B = D = 0;
        for(auto j: mp[i]) {
            if(j==1) ++R;
            else if(j==0) ++D;
            else ++B;
        }
        // if(i==2) trace(R,B,D);
        if(R>0 && B>0) ok = 0;
        else if(D>0 && R==0 && B==0) {ans *= 2;ans %= mod;}
    }

    if(!ok) ans = 0;
    cout << ans << "\n";



    auto end_time = Clock;
    #ifndef TIME
        return 0;
    #endif
    cout << "\nTime elapsed: "
    << (double)duration_cast<milliseconds>(end_time-start_time).count() 
    << "ms";


    return 0;
}
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i = 0; i < (n); ++i)
#define DREP(i,s,n) for(int i = (s); i < (n); i++)
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;
const int MOD = 998244353;
const double pi = acos(-1);
ll gcd(ll a, ll b) {if(b == 0) return a; else return gcd(b,a%b);}
ll lcm(ll a, ll b) {return a*b/gcd(a,b);}

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

int main() {
    int H,W; cin >> H >> W;
    vector<string> S(H);
    REP(i,H) cin >> S[i];
    int cnt = 0;

    REP(j,W) {
        set<char> st;
        for(int i = 0,k = j; i < H &&  k >= 0; i++,k--) {
                st.insert(S[i][k]);
        }
        if(st.count('R') && st.count('B')) {
            cout << 0 << endl;
            return 0;
        } if(st.size() == 1 && st.count('.')) cnt++;
    }

    REP(i,H) {
        if(i == 0) continue;
        set<char> st;
        for(int k = i,j = W-1; k < H && j >= 0; k++,j--) {
            st.insert(S[k][j]);
        }
        if(st.count('R') && st.count('B')) {
            cout << 0 << endl;
            return 0;
        } if(st.size() == 1 && st.count('.')) cnt++;
    }
    cout << modpow(2LL,cnt,MOD) << endl;
    return 0;
}