#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;
}
#include <bits/stdc++.h>
using namespace std;

const int64_t inf = 998244353;

int main() {
    int H, W, HW, k=1;
    int64_t ans = 1;
    cin >> H >> W;
    HW = H + W - 1;
    string S, AllS;
    vector<int> vec(HW);
    bool f = true;
    cin >> S;
    AllS = S;
    for(int i = 1; i < H; i++){
        cin >> S;
        if(!f) continue;
        for(int j = 0; j < W-1; j++){
            if(S.at(j) == '.') continue;
            if(AllS.at(j+k) == '.'){
                AllS.at(j+k) = S.at(j);
                continue;
            }
            if(S.at(j) != AllS.at(j+k)){
                ans = 0;
                f = false;
                break;
            }
        }
        AllS += S.at(W-1);
        k++;
    }
    if(!f) cout << '0' << endl;
    else{
        for(auto c: AllS){
            if(c == '.'){
                ans = (ans*2)%inf;
            }
        }
        cout << ans << endl;
    }
}
