#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define eb emplace_back
using namespace std;
template <class T = int>
using V = vector<T>;
template <class T = int>
using VV = V<V<T>>;
using ll = long long;
using ld = long double;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using pdd = pair<ld,ld>;

const int mod = 998244353;
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) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int h, w;
    cin >> h >> w;
    V<string> f(h);
    rep(i,h) cin >> f[i];
    mint ans = 1;
    rep(i,h+w-1){
        int y = min(w-1, i);
        int x = i-y;
        //cout << x << y << endl;
        V<int> cnt(3);
        while(1){
            if(x >= h || y < 0) break;
            if(f[x][y] == 'R') cnt[0]++;
            if(f[x][y] == 'B') cnt[1]++;
            if(f[x][y] == '.') cnt[2]++;
            x++, y--;
        }
        int c = 0;
        rep(j,3) if(cnt[j] > 0) c++;
        //cout << c << endl;
        if(c == 3){
            cout << 0 << endl;
            return 0;
        }
        if(c == 2 && cnt[2] == 0){
            cout << 0 << endl;
            return 0;
        }
        if(c == 1 && cnt[2] > 0) ans *= 2;
    }
    cout << ans << endl;
}
#include <bits/stdc++.h>
using namespace std;
#define REPP(i,a,b,d) for(int i=(a);i<=(int)(b);i+=(d))
#define REP(i,a,b) REPP(i,a,b,1)
#define REVV(i,a,b,d) for(int i=(a);i>=(int)(b);i-=(d))
#define REV(i,a,b) REVV(i,a,b,1)
#define FOR(i,a) for(int i=0; i<(int)(a); i++)
#define FORD(i,a) for(int i=(int)(a)-1; i>=0; i--)
#define pb push_back
typedef long long ll;

const int N = 3005;
const ll MOD = 998244353;
int n, k;
ll memo[N][N];

ll dp(int n, int m) {
	if(n < m) return 0;
	if(m == 0) return (n == 0);
	ll &ret = memo[n][m];
	if(ret != -1) return ret;
	return ret = (dp(n, 2*m) + dp(n-1, m-1)) % MOD;
}

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> n >> k;
	memset(memo, -1, sizeof memo);
	cout << dp(n, k) << '\n';
	return 0;
}