#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1<<30;
const ll inf_l = 1LL<<61;
const int MAX = 1e5;

const int mod = 1e9 + 7;
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 {return mint(*this) += a;}
    mint operator -(const mint a) const {return mint(*this) -= a;}
    mint operator *(const mint a) const {return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }
    mint inv() const {return pow(mod - 2);}
    mint operator /=(const mint a) {return *this *= a.inv();}
    mint operator /(const mint a) {return mint(*this) /= a;}
};
istream& operator >>(istream &is, mint &a) {return is >> a.x;}
ostream& operator <<(ostream &os, const mint &a) {return os << a.x;}

mint dp[2005][2005];
mint sum_v[2005][2005];
mint sum_h[2005][2005];
mint sum_d[2005][2005];

int main() {
    int h, w; cin >> h >> w;
    vector<string> field(h);
    rep(i,h) cin >> field[i];
    sum_v[1][1] = 1;
    sum_h[1][1] = 1;
    sum_d[1][1] = 1;
    dp[1][1] = 1;
    REP(i,h+1)REP(j,w+1) {
        if (field[i - 1][j - 1] == '#') continue;
        if (i == 1 && j == 1) continue;
        dp[i][j] = sum_v[i - 1][j] + sum_h[i][j - 1] + sum_d[i - 1][j - 1];
        sum_v[i][j] = sum_v[i - 1][j] + dp[i][j];
        sum_h[i][j] = sum_h[i][j - 1] + dp[i][j];
        sum_d[i][j] = sum_d[i - 1][j - 1] + dp[i][j];
    }
    cout << dp[h][w] << endl;
}
#include <bits/stdc++.h>
#define endl '\n'
#define INF 0x3f3f3f3f
#define Inf 1000000000000000000LL
#define int long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
using namespace std;
typedef pair<int,int>pii;
int n,m;
char a[510][510];
int cntr,cntb;
signed main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++)cin>>(a[i]+1);
	for(int i=1;i<=m;i++){
		bool flgr=0,flgb=0;
		for(int x=1,y=i;x<=n&&y>=1;x++,y--){
			if(a[x][y]=='R')flgr=1;
			if(a[x][y]=='B')flgb=1;
		}
		if(flgr==1&&flgb==1)return puts("0"),0;
		if(flgr==1)cntr++;
		if(flgb==1)cntb++;
	}
	for(int i=2;i<=n;i++){
		bool flgr=0,flgb=0;
		for(int x=i,y=m;x<=n&&y>=1;x++,y--){
			if(a[x][y]=='R')flgr=1;
			if(a[x][y]=='B')flgb=1;
		}
		if(flgr==1&&flgb==1)return puts("0"),0;
		if(flgr==1)cntr++;
		if(flgb==1)cntb++;
	}
	int t=n+m-1LL-cntr-cntb;
//	cout<<t<<endl;
	int ans=1LL;
	for(int i=1;i<=t;i++)ans=ans*2LL%998244353LL;
	cout<<ans<<endl;
	return 0;
}
/*
rrb
rbr
brr



r.r
.br
...



#####
#####
#####
*/
