#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<tuple>
#include<cstring>
#include<bitset>

#define REP(i,n) for(ll i=0;i<(ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((ll)(x).size())
#define pb push_back
#define eb emplace_back

#define INF 1000000000
#define INFLL 1000000000000000000LL

using namespace std;

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; }

using ll = long long;
using P = pair<ll, ll>;

#define MAX_H 500+10
#define MAX_W 500+10
#define MOD 998244353

ll H, W, ans;
string S[MAX_H];
set<char> A[10000];

int main() {

	cin >> H >> W;
	REP(i, H)cin >> S[i];


	REP(i, H) {
		REP(j, W) {
			A[i + j].insert(S[i][j]);
		}
	}

	ans = 1;

	REP(i, 10000) {
		bool r = false, b = false, w = false;
		for (auto&& x : A[i]) {
			if (x == 'R')r = true;
			if (x == 'B')b = true;
			if (x == '.')w = true;
		}
		if (r && b)ans = 0;
		if (w && !b && !r)ans = ans * 2 % MOD;
	}

	cout << ans << endl;

	return 0;
}
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i, a, b) for(ll i = a; i < b; i++)
#define rep(i, n) FOR(i, 0, n)
#define rFOR(i, a, b) for(ll i = a - 1; i >= b; i--)
#define rrep(i, a) rFOR(i, a, 0)
#define pb push_back
using namespace std;
using ll = long long;
using ld = long double;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<char> vc;
typedef vector<vc> vvc;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const ld PI = acos(-1);
const ll INF = 1e18;
struct edge{ll to, cost;};

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

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

vl memo(5000000,-1);

long long mod_pow(long long x, long long y, long long M){
    if(memo[y]!=-1){
        return memo[y];
    }
    if(y == 0){
        memo[y]=1;
        return 1;
    }
    if(y & 1){
        return memo[y]=mod_pow(x, y - 1, M) * x % M;
    }
    long long t = mod_pow(x, y / 2, M);
    return memo[y] = t * t % M;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int H,W;
    cin >> H >> W;
    vvc c(H,vc(W));
    ll base=0;
    rep(i,H){
        rep(j,W){
            cin >> c[i][j];
            if(c[i][j]=='.'){
                base++;
            }
        }
    }
    ll ans=0;
    vvl yoko(H,vl(W));
    vvl tate(H,vl(W));
    rep(i,H){
        int res=0;
        int now=0;
        rep(j,W){
            if(c[i][j]=='#'){
                FOR(k,res,j){
                    yoko[i][k]=now;
                }
                res=j+1;now=0;
            }
            else{
                now++;
            }
        }
        FOR(k,res,W){
            yoko[i][k]=now;
        }
    }
    rep(i,W){
        int res=0;
        int now=0;
        rep(j,H){
            if(c[j][i]=='#'){
                FOR(k,res,j){
                    tate[k][i]=now;
                }
                res=j+1;now=0;
            }
            else{
                now++;
            }
        }
        FOR(k,res,H){
            tate[k][i]=now;
        }
    }
    /*rep(i,H){
        rep(j,W){
            cout << yoko[i][j];
        }
        cout << '\n';
    }
    rep(i,H){
        rep(j,W){
            cout << tate[i][j];
        }
        cout << '\n';
    }*/
    rep(i,H){
        rep(j,W){
            if(c[i][j]=='.'){
                ans+=mod_pow(2,base-tate[i][j]-yoko[i][j]+1,MOD)*(mod_pow(2,tate[i][j]+yoko[i][j]-1,MOD)-1)%MOD;
                ans%=MOD;
            }
        }
    }
    cout << ans << endl;
}