#include "bits/stdc++.h"
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define endl '\n'
#define all(V) (V).begin(), (V).end() 
using namespace std;
typedef long long ll;
const ll mod = 998244353;
int main() {fio;
	int n, m;
	cin >> n >> m;
	vector <string> a(n);
	vector <set <char> > oh(n + m);
	for(int i = 0; i < n; i++) {
		cin >> a[i];
		for(int j = 0; j < a[i].size(); j++) {
			if(a[i][j] != '.') {
				oh[i + j].insert(a[i][j]);
			}
		}
	}
	ll ans = 1;
	for(int i = 0; i <= n + m - 2; i++) {
		 if(oh[i].size() == 2) {
		 	cout << 0;
		 	return 0;
		 }
		 if(oh[i].size() == 1) {
		 	continue;
		 }
		 ans = (ans * 2) % mod;
	}
	cout << ans << endl;
    return 0;
}
//region TEMPLATE
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
#define fastio ios_base::sync_with_stdio(0);cin.tie(NULL);
#define endl "\n"
#define pb push_back
#define all(X) begin((X)), end((X))
#define sz(X) (int)(X).size()
#define fi first
#define se second
#define fv(X) for(auto&_:(X))cin>>_
#define fv2(X) for(auto&__:(X))fv(__)
#define lboundi(X, n) (lower_bound(all(X), n) - begin(X))
#define uboundi(X, n) (upper_bound(all(X), n) - begin(X))
#define maxi(X) max_element(all(X)) - begin(X)
#define maxe(X) *max_element(all(X))
#define mini(X) min_element(all(X)) - begin(X)
#define mine(X) *min_element(all(X))
#define acc(X) accumulate(all(X), 0LL)
#ifdef LOCAL
template<size_t S>
string to_string(const bitset<S> &x) { return x.to_string(); }
string to_string(const string &x) { return '"' + x + '"'; }
string to_string(char x) { return string{'\'', x, '\''}; }
string to_string(bool x) { return x ? "true" : "false"; }
template<typename Head, typename Tail>
string to_string(const pair<Head, Tail> &x) { return "(" + to_string(x.first) + ", " + to_string(x.second) + ")"; }
template<class T>
string to_string(T x) {
    string ret = "[";
    for (const auto &i: x)
        ret += to_string(i) + ", ";
    if (sz(ret) > 1)
        ret = ret.substr(0, sz(ret) - 2);
    return ret += "]";
}
string to_string(const char *x) { return string(x); }
string to_string() { return ""; }
template<typename Head, typename... Tail>
string to_string(Head H, Tail... T) { return to_string(H) + ", " + to_string(T...); }
#define debug(...) sizeof( (char[]){#__VA_ARGS__} ) == 1 ? cerr << endl \
: cerr << "[" << #__VA_ARGS__ << "]: " << to_string(__VA_ARGS__) << endl
#define nr() cerr << endl
#else
#define debug(...) 1
#endif
// endregion
const ll mod = 998244353;
void solve() {
    int Y, X;
    cin >> Y >> X;
    vs board(Y);
    fv(board);

    ll ret = 0;

    // 무조건 Y + X - 1 칸을 밟아야 함

    // Y + X - 1 개의 대각선 색을 조절
    // 그중 하나라도 조절 못하는 것이 있다면 정답은 0

    // 0 -> 둘다 가능, 1 -> 하나만 가능
    vi color(X + Y - 1);
    int sy = 0, sx = 0;
    for (int i = 0; i < X + Y - 1; i++) {
        bool r = false, b = false;

        int y = sy, x = sx;
        while (y >= 0 && x < X) {
            if (board[y][x] == 'R') {
                r = true;
            }
            if (board[y][x] == 'B')
                b = true;
            if (r && b) {
                cout << 0;
                return;
            }
            y--;
            x++;
        }
        if (!r && !b) {
            color[i] = 0;
        } else {
            color[i] = 1;
        }

        if (sy < Y - 1)
            sy++;
        else
            sx++;
    }

    int controllable = count(all(color), 0);
    ret = 1;
    while (controllable--) {
        ret *= 2;
        ret %= mod;
    }
    cout << ret;
}

// .A.
// B..
// ...

int main() {
    fastio
    solve();
    return 0;
}