#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define MOD 998244353 
using namespace std;
using ll = long long;

template<int M>
class ModInt {
   public:
    ll value;
    constexpr ModInt(ll v = 0) { value = v % M; if (value < 0) value += M; }
    constexpr ModInt pow(ll n) const { if (!n) return 1; ModInt a = pow(n >> 1); a *= a; if (n & 1) a *= *this; return a; }
    constexpr ModInt inv() const { return this->pow(M - 2); }
    constexpr ModInt operator + (const ModInt &rhs) const { return ModInt(*this) += rhs; };
    constexpr ModInt operator - (const ModInt &rhs) const { return ModInt(*this) -= rhs; };
    constexpr ModInt operator * (const ModInt &rhs) const { return ModInt(*this) *= rhs; };
    constexpr ModInt operator / (const ModInt &rhs) const { return ModInt(*this) /= rhs; };
    constexpr ModInt &operator += (const ModInt &rhs) { value += rhs.value; if (value >= M) value -= M; return *this; };
    constexpr ModInt &operator -= (const ModInt &rhs) { value -= rhs.value; if (value <  0) value += M; return *this; };
    constexpr ModInt &operator *= (const ModInt &rhs) { value = value * rhs.value % M; return *this; };
    constexpr ModInt &operator /= (const ModInt &rhs) { return (*this) *= rhs.inv(); };
    constexpr bool operator == (const ModInt &rhs) { return value == rhs.value; }
    constexpr bool operator != (const ModInt &rhs) { return value != rhs.value; }
    friend ostream &operator << (ostream &os, const ModInt &rhs) { os << rhs.value; return os; }
};

using mint = ModInt<MOD>;

int main() {
    int H, W; cin >> H >> W;
    vector<string> S(H);
    REP(i, 0, H) cin >> S[i];

    auto diag = [&](int h, int w) -> int {
        int c = 0;
        while (h < H && w >= 0) {
            int nc = 0;
            if (S[h][w] == 'R') nc = 1;
            else if (S[h][w] == 'B') nc = 2;

            if (c && nc && c != nc) return -1;
            if (!c) c = nc;
            h++; w--;
        }
        return c;
    };

    int cnt = 0;
    REP(i, 0, W) {
        int c = diag(0, i);
        if (c == -1) {
            cout << 0 << endl;
            return 0;
        } else if (c == 0) {
            cnt++;
        }
    }
    REP(i, 1, H) {
        int c = diag(i, W - 1);
        if (c == -1) {
            cout << 0 << endl;
            return 0;
        } else if (c == 0) {
            cnt++;
        }
    }

    cout << mint(2).pow(cnt) << endl;
    
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define BE(x) x.begin(), x.end()

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    for (auto &x : s) cin >> x;

    vector<bitset<2>> cnt;
    for (int j = 0; j < w; j++) {
        bitset<2> bs;
        int jj = j;
        for (int i = 0; jj >= 0 && i < h; i++, jj--) {
            if (s[i][jj] == 'R') bs[0] = true;
            else if (s[i][jj] == 'B') bs[1] = true;
        }
        cnt.push_back(bs);
    }
    for (int i = 1; i < h; i++) {
        bitset<2> bs;
        int ii = i;
        for (int j = w-1; ii < h && j >= 0; ii++, j--) {
            if (s[ii][j] == 'R') bs[0] = true;
            else if (s[ii][j] == 'B') bs[1] = true;
        }
        cnt.push_back(bs);
    }

    ll ans = 1;
    for (auto &x : cnt) {
        if (x[0] && x[1]) {
            cout << 0 << endl;
            return 0;
        }
        else if (!(x[0] || x[1])) {
            ans = ans * 2LL % 998244353LL;
        }
    }
    cout << ans << endl;
}