#include<bits/stdc++.h>
#define int long long
#define rint regester int
const int maxn = 500 + 10;
const int mod = 998244353;
using std::ios;
using std::cin;
using std::cout;
using std::max;
using std::min;
using std::sort;
using std::unique;
using std::lower_bound;
using std::swap;
using std::abs;
using std::acos;
using std::queue;
using std::map;
using std::string;
int read(){int x = 0,f = 1; char ch = getchar(); while(ch < '0' || ch > '9'){if(ch == '-')f = -1; ch = getchar();}while(ch >= '0' && ch <= '9'){x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar();} return x * f;}
int h, w, p[maxn][maxn], ans = 1;
string s[maxn];
signed main(){
	h = read(), w = read();
	for(int i = 1; i <= h; i++)cin >> s[i];
	for(int i = 1; i <= h; i++){
		for(int j = 0; j < w; j++){
			if(s[i][j] == 'R')p[i][j + 1] = 1;else
			if(s[i][j] == 'B')p[i][j + 1] = 2;else p[i][j + 1] = 0;
		}
	}
	for(int i = 2; i <= h + w; i++){
		int c = 0, pp = 0;
		for(int j = max(1ll, i - w); j < i && j <= h; j++){
			++pp;
			int k = i - j;
			if(p[j][k] == 1){if(c == 2){cout << 0; return 0;} c = 1;}else
			if(p[j][k] == 2){if(c == 1){cout << 0; return 0;} c = 2;}
		}
		if(c == 0){
			ans *= 2;
			ans %= mod;
		}
	}
	cout << ans;
}
/*
ID: gurban1
LANG: C++
TASK: 
*/
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

const int N = 24;
const int maxn=2e5+5;
const int mod=998244353;
int n,m;
ll dp[maxn][N];
ll f[maxn],ans;

ll binmod(ll a,ll b) {if(b==0)return 1;ll x=binmod(a*a%mod,b>>1);return b&1?x*a%mod:x;}

ll inv(ll a){
	return binmod(a,mod-2);
}

ll choose(int a,int b){
	if(a < b) return 0;
	ll x = (f[a] * inv(f[b])) % mod;
	x = (x * inv(f[a-b]))%mod;
	return x;
}

int main(){
	// freopen("","r",stdin);
	// freopen("","w",stdout);

	ios::sync_with_stdio(false);
	cin.tie(0);

	cin >> n >> m;
	
	f[0] = 1;
	for(int i = 1;i <= n;i++) f[i] = (f[i-1] * i) % mod;

	for(int i = m;i >= 1;i--){
		dp[i][1] = 1;
		for(int j = i+i;j <= m;j += i)
			for(int k = 1;k < N;k++) dp[i][k+1] += dp[j][k];
		for(int j = 1;j < N;j++){
			if(j > n) break;
			ll nw = (dp[i][j] * choose(n-1,j-1)) % mod;
			ans = (ans + nw) % mod;
		}
	}
	cout<<ans;
}