#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 998244353
 
void solve(){

	int H, W; cin>>H>>W;
	//set<int> s;
	int a[H][W];
	int sum[10001] = {0};
	int chk = 1;
	for(int i = 0; i<H; i++){
		string S; cin>>S;
		for(int j = 0; j<W; j++){
			if(S[j]=='R'){
				if(sum[i+j]!=0&&sum[i+j]!=1) chk = 0;
				else sum[i+j] = 1;
			}
			else if(S[j]=='B'){
				if(sum[i+j]!=0&&sum[i+j]!=-1) chk = 0;
				else sum[i+j] = -1;
			}
		}
	}
	if(!chk){
		cout<<0;
		return;
	}
	int ans = 1;
	for(int i = 0; i<H+W-1; i++){
		if(sum[i]==0){
			ans*=2;
			ans%=mod;
		}
	}
	cout<<ans<<'\n';

}


int main(){

ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);

//  #ifndef ONLINE_JUDGE

//  freopen("input.txt", "r", stdin);

//  freopen("output.txt", "w", stdout);

//  #endif // ONLINE_JUDGE

 //int t; cin>>t;
 int t = 1;
 for(int i =0 ; i<t; i++) 
	solve();
return 0;


}
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+5;
const int mod=1e9+7;
int h,w;
char s[2003][2003];
int dp[2003][2003];
int s1[2003][2003],s2[2003][2003],s3[2003][2003];
int main(){
    ios::sync_with_stdio(false);
    cin>>h>>w;
    for(int i=1;i<=h;i++)
        cin>>s[i]+1;

    dp[1][1]=1;s1[1][1]=1;
    s2[1][1]=1;s3[1][1]=1;

    for(int i=1;i<=h;i++)
        for(int j=1;j<=w;j++){
            if(s[i][j]=='#')continue;

        dp[i][j]+=(s2[i-1][j]+s1[i][j-1])%mod;
        dp[i][j]=(dp[i][j]+s3[i-1][j-1])%mod;

        s1[i][j]=(s1[i][j-1]+dp[i][j])%mod;
        s2[i][j]=(s2[i-1][j]+dp[i][j])%mod;
        s3[i][j]=(s3[i-1][j-1]+dp[i][j])%mod;
        //printf("dp[%d][%d]=%d\n",i,j,dp[i][j]);

        }

    printf("%d\n",dp[h][w]);
    return 0;
}
