///Bismillahir Rahmanir Rahim
#include "bits/stdc++.h"

#define                           ll                          long long
#define                           int                         ll
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<int,int>
#define                           nd(a,b,c)                   mp(mp(a,b),c)
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           show(x,y)                   cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

const ll inf=2e18;
const int mod=998244353;
const int M=100005;
void solve()
{
   int h,w;
   cin>>h>>w;
   char yo[h+1][w+1];
   f(i,1,h)
   {
       f(j,1,w)
       {
           cin>>yo[i][j];
       }
       cin.ignore();
   }
   int ses=1;
   vector<pi>vec;
   for(int i=1;i<=h;i++)vec.pb({i,1});
   for(int j=2;j<=w;j++)vec.pb({h,j});
   for(auto z:vec)
   {
       int x=z.fi,y=z.si;
       int red=0,blue=0,no_colour=0;
       while(x>=1 && y<=w)
       {
             if(yo[x][y]=='B')blue++;
             else if(yo[x][y]=='R')red++;
             else no_colour++;
             x--;y++;
       }
       if(red>=1 && blue>=1)
       {
           cout<<"0\n";return ;
       }
       if(red==0 && blue==0)ses=(ses*2LL)%mod;
   }

   cout<<ses<<"\n";
}
 main()

{
    fast
    int t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;

}




































#include <bits/stdc++.h>
#define rep(i,x,y) for(int i=x;i<=y;++i)
#define per(i,x,y) for(int i=x;i>=y;--i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int inf = 1e9;
const int mod=1e9+7;
const int N = 3e5 + 5;
int n;
int a[N];
int tr[N];
void add(int x,int k){
    while(x<=n) tr[x]+=k,x+=x&-x;
}
int dor(int x){
    int ret=0;
    while(x) ret+=tr[x],x-=x&-x;
    return ret;
}
int main() {
    cin>>n;
    rep(i,1,n){
        cin>>a[i];
        a[i]++;
    }
    ll ans=0;
    rep(i,1,n){
        ans+=dor(n)-dor(a[i]);
        add(a[i],1);
    }
    cout<<ans<<'\n';
    rep(i,1,n-1){
        ans+=dor(n)-dor(a[i]);
        ans-=dor(a[i]-1);
        cout<<ans<<'\n';
    }
    return 0;
}