#include<bits/stdc++.h>
using namespace std;
const int mx=505;
const int mod=998244353;
int n,m,dp[mx][mx];
long long tmp=1;
char a[mx][mx];
int main() {
//	freopen("data.in","r",stdin);
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++) scanf("%s",a[i]+1);
	for(int i=1;i<=n;i++) {
		int col=0,col2=0;
		for(int j=0;i-j>=1&&j+1<=m;j++) {
			if(a[i-j][j+1]=='B') {col=1;}
			if(a[i-j][j+1]=='R') {col2=1;}
		}
		if(!col&&!col2) tmp*=2,tmp%=mod;
		else if(col&&col2) {
			printf("0");
			return 0;
		}
	}
	for(int i=2;i<=m;i++) {
		int col=0,col2=0;
		for(int j=0;n-j>=1&&i+j<=m;j++) {
			if(a[n-j][i+j]=='B') {col=1;}
			if(a[n-j][i+j]=='R') {col2=1;}
		}
		if(!col&&!col2) tmp*=2,tmp%=mod;
		else if(col&&col2) {
			printf("0");
			return 0;
		}
	}
	printf("%lld",tmp);
} 
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i,a,b) for (ll i = (a); i < (ll)(b); i++)
#define rng(x) (x).begin(), (x).end()
#define rrng(x) (x).rbegin(), (x).rend()
#define popcnt(x) __builtin_popcountll(x)
#define pb push_back
#define eb emplace_back
#define fr first
#define sc second

using namespace std;
template <class T, class U> inline bool chmax(T &a, const U &b) { return (a < b ? a = b, 1 : 0); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return (a > b ? a = b, 1 : 0); }
template <class T> using vc = vector<T>;
template <class T> using vv = vc<vc<T>>;
template <class T> using vvv = vc<vv<T>>;
template <class T> using PQ = priority_queue<T, vc<T>, greater<T>>;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;
using ti3 = tuple<int, int, int>;
using tl3 = tuple<ll, ll, ll>;
using vi = vc<int>;
using vl = vc<ll>;
using vpl = vc<pll>;
using vvi = vv<int>;
using vvl = vv<ll>;

const ld pi = 3.141592653589793;
const ll linf = 1001001001001001001LL;
const int inf = 1001001001;

vi dx = {1, 0}, dy = {0, 1};

int main() {
  ll h, w;
  cin >> h >> w;
  vc<string> s(h);
  rep(i,h) cin >> s[i];
  vvl dist(h, vl(w, linf));
  dist[0][0] = 0;
  queue<pll> que;
  que.emplace(0, 0);
  while(!que.empty()) {
    auto [y, x] = que.front();
    que.pop();
    rep(i,2) {
      ll ny = y+dy[i], nx = x+dx[i];
      if (0 <= ny && ny < h && 0 <= nx && nx < w && dist[ny][nx] == linf) {
        dist[ny][nx] = dist[y][x]+1;
        que.emplace(ny, nx);
      }
    }
  }
  vpl state(h+w-1);
  rep(i,h) rep(j,w) {
    auto &[R, B] = state[dist[i][j]];
    if (s[i][j] != '.') (s[i][j] == 'R' ? R : B) += 1;
  }
  ll ans = 1;
  const ll mod = 998244353;
  rep(i,h+w-1) {
    auto [R, B] = state[i];
    if (R >= 1 && B >= 1) ans *= 0;
    else if (R >= 1 || B >= 1) ans *= 1;
    else ans *= 2;
    ans %= mod;
  }
  cout << ans << endl;
}