#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 998244353;
typedef long long LL;
typedef pair<int, int> P;

template<typename T>
istream& operator >> (istream& is, vector<T>& vs){
  for(T& v: vs) is >> v;
  return is;
}

int main() {
  int H, W; cin >> H >> W;
  vector<string> S(H); cin >> S;
  vector<vector<int>> C(H, vector<int>(W, 0));

  for (int c = 1; c < W; ++c) {
    C[0][c] = C[0][c-1] + 1;
  }
  for (int r = 1; r < H; ++r) {
    for (int c = 0; c < W; ++c) {
      C[r][c] = C[r-1][c] + 1;
    }
  }

  map<int, char> m;
  for (int r = 0; r < H; ++r) {
    for (int c = 0; c < W; ++c) {
      int x = C[r][c];
      char y = S[r][c];
      if (m.count(x)) {
        if (m[x] != y && y != '.') {
          if (m[x] == '.') {
            m[x] = y;
          } else {
            cout << 0 << endl;
            return 0;
          }
        }
      } else {
        m[x] = S[r][c];
      }
    }
  }

  LL ans = 1;
  for (const auto& [i, c] : m) {
    if (c == '.') {
      ans = ans * 2LL;
      ans %= kMod;
    }
  }
  cout << ans << endl;
}

#include<set>
#include<queue>
#include<cmath>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define MAXN 505
#define ENDL putchar('\n')
#define LL long long
#define DB double
#define lowbit(x) ((-x) & (x))
LL read() {
	LL f = 1,x = 0;char s = getchar();
	while(s < '0' || s > '9') {if(s=='-')f = -f;s = getchar();}
	while(s >= '0' && s <= '9') {x=x*10+(s-'0');s = getchar();}
	return f * x;
}
const int MOD = 998244353;
int n,m,i,j,s,o,k;
char ss[MAXN][MAXN];
int tg[MAXN<<1];
int main() {
	n = read(); m = read();
	for(int i = 1;i <= n;i ++) {
		scanf("%s",ss[i] + 1);
		for(int j = 1;j <= m;j ++) {
			if(ss[i][j] == 'B') {
				if(tg[i+j] > 0) {printf("0\n");return 0;}
				tg[i+j] = -1;
			}
			else if(ss[i][j] == 'R') {
				if(tg[i+j] < 0) {printf("0\n");return 0;}
				tg[i+j] = 1;
			}
		}
	}
	int ans = 1;
	for(int i = 2;i <= n+m;i ++) {
		if(tg[i] == 0) (ans += ans) %= MOD; 
	}
	printf("%d\n",ans);
	return 0;
}