#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
const ll MOD=998244353;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  int H,W;
  cin>>H>>W;
  vector<string> S(H);
  rep(i,H) cin>>S[i];

  vector<vector<pair<int,int>>> v(H+W);
  rep(i,H) rep(j,W) v[i+j].push_back(mkp(i,j));

  ll ans=1;
  for(int k=0;k<H+W-1;k++){
    ll r=0,b=0;
    ll c=0;
    for(auto [i,j]:v[k]){
      if(S[i][j]=='R') r++;
      else if(S[i][j]=='B') b++;
      else c++;
    }

    if(r>0&&b>0) ans=0;
    else if(r>0||b>0);
    else{
      ans=ans*2%MOD;
    }
  }

  cout<<ans<<endl;

  return 0;
}

#include<bits/stdc++.h>
using namespace std;

typedef long long LL;

const int N=500,mod=998244353;

int n,m;
char s[N+9][N+9];

void into(){
  scanf("%d%d",&n,&m);
  for (int i=1;i<=n;++i)
	scanf("%s",s[i]+1);
}

int cnt[N*2+9][3],ans;

void Get_ans(){
  for (int i=1;i<=n;++i)
	for (int j=1;j<=m;++j) ++cnt[i+j][s[i][j]=='R'?2:s[i][j]=='B'];
  ans=1;
  for (int i=2;i<=n+m;++i){
	if (cnt[i][1]&&cnt[i][2]) ans=0;
	if (!cnt[i][1]&&!cnt[i][2]) ans=1LL*ans*2%mod;
  }
  printf("%d\n",ans);
}

void work(){
  Get_ans();
}

void outo(){
}

int main(){
  int T=1;
  //scanf("%d",&T);
  for (;T--;){
	into();
	work();
	outo();
  }
  return 0;
}