#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;
#define rep(i,n) for(ll i=0;i<(n);++i)
#define rep2(i,n) for(ll i=1;i<=(n);++i)
#define rep3(i,i0,n) for(ll i=i0;i<(n);++i)
#define rrep(i,n) for(ll i=((n)-1); i>=0; --i)
#define rrep2(i,n) for(ll i=(n); i>0; --i)
#define pb push_back
#define mod 998244353
#define fi first
#define se second
#define len(x) ((ll)(x).size())
using namespace std;
using ll = long long;
using ld = long double;
using Pi = pair< ll, ll >;
using vl = vector<ll>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vp = vector<Pi>;
using vvc = vector<vector<char>>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

const ll INF = 1LL << 60;
const ld PI = 3.1415926535897932385;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define mp make_pair
void printb(ll N,ll d=16){
    rep(i,d){
        cout<<(N/(1<<(d-i-1)))%2;
    }
    cout<<endl;
    
}
void printv(vector<ll>a){
    rep(i,a.size()){
        if(i==a.size()-1){
            cout<<a[i]<<endl;
        }else{
            cout<<a[i]<<" ";
        }
    }
}
bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


//const vector<ll> dx = {1, 0, -1, 0, 1, -1, 1, -1};
//const vector<ll> dy = {0, 1, 0, -1, 1, 1, -1, -1};
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};

template <std::uint_fast64_t Modulus> class modint {
  using u64 = std::uint_fast64_t;

public:
  u64 a;

  constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  constexpr u64 &value() noexcept { return a; }
  constexpr const u64 &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};
using mint = modint<mod>;
using vm = vector<mint>;
using vvm = vector<vector<mint>>;
int main() {
    ll H,W;
    cin>>H>>W;

    vs S(H);

    rep(i,H){
        cin>>S[i];
    }

    mint ans=1;

    rep(i,H+W-1){
        ll rf=0,bf=0;

        rep(j,H){
            if(i-j<0 || i-j>=W)continue;
            if(S[j][i-j]=='R'){
                rf=1;
            }else if(S[j][i-j]=='B'){
                bf=1;
            }
        }

        ans*=(2-rf-bf);
    }


    cout<<ans.a<<endl;



    return 0;
    

}
#include <bits/stdc++.h>
#ifdef LOCAL
#include "prettyprint.hpp"
#else
#define deb(...)
#endif
using namespace std;
using ll = long long;

const int mod = 998244353;

int main()
{
    cin.tie(0)->sync_with_stdio(0);
    // cout << fixed << setprecision(15);

    int h, w;
    cin >> h >> w;
    vector<vector<char>> g(h, vector<char>(w));
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin >> g[i][j];
        }
    }

    vector<vector<char>> diagnol(2 * max(h, w));
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            diagnol[i+j].push_back(g[i][j]);
        }
    }
    ll sum = 1;

    for (auto i : diagnol) {
        bool onlydots = true;
        bool red = false;
        bool blue = false;
        int dotcount = 0;
        for (auto j: i) {
            if (j == '.') dotcount++;
            if (j == 'R') {
                onlydots = false;
                red = true;
            }
            if (j == 'B') {
                onlydots = false;
                blue = true;
            }
        }
        if (red && blue) {
            sum *= 0;
            break;
        }
        if (dotcount == 0) {
            continue;
        }
        if (red || blue) {
            sum *= 1;
            continue;
        }
        sum = sum * 2;
        sum %= mod;
    }
    cout << sum << "\n";
    return 0;
}
