#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
//constexpr ll MOD = 1e9 + 7;
constexpr ll MOD = 998244353;
//constexpr ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
constexpr ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
#define FINALANS(A) do {cout << (A) << '\n'; exit(0);} while (false)

int main()
{
  vector<ll> P = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29,
                  31, 37, 41, 43, 47, 53, 59, 61, 67, 71};

  ll K = P.size();

  ll A, B;
  cin >> A >> B;
  ll N = B - A + 1;

  vector<ll> bb(N, 0);
  for (ll i = 0; i < N; i++)
  {
    for (ll j = 0; j < K; j++)
    {
      if ((A + i) % P.at(j) == 0)
        bb.at(i) ^= (1LL << j);
    }
  }

  vector<vector<ll>> dp(N + 1, vector<ll>((1LL << K), 0));
  dp.at(0).at(0) = 1;
  for (ll i = 0; i < N; i++)
  {
    for (ll b = 0; b < (1LL << K); b++)
    {
      dp.at(i + 1).at(b) += dp.at(i).at(b);
      
      if ((b & bb.at(i)) == 0)
        dp.at(i + 1).at(b ^ bb.at(i)) += dp.at(i).at(b);
    }
  }

  ll ans = 0;
  for (ll b = 0; b < (1LL << K); b++)
  {
    ans += dp.at(N).at(b);
    //cerr << dp.at(N).at(b) << endl;
  }
  cout << ans << endl;
}
//Har Har Mahadev
using namespace std;
#include <bits/stdc++.h>
#define booga cerr << "booga" << endl
#define int long long 
#define ld long double
#define pb push_back
#define mp make_pair
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define safai(...) Clearing_out(__VA_ARGS__)


template <typename A, typename B>
	string to_string(pair<A, B> p);
 
template <typename A, typename B, typename C>
	string to_string(tuple<A, B, C> p);
 
template <typename A, typename B, typename C, typename D>
	string to_string(tuple<A, B, C, D> p);
 
string to_string(const string& s) {
	return '"' + s + '"';
}

string to_string(char c) {
	string s;
	s += c;
	return s;
}

string to_string(const char* s) {
	return to_string((string) s);
}
 
string to_string(bool b) {
	return (b ? "1" : "0");
}
 
string to_string(vector<bool> v) {
	bool first = true;
	string res = "{";
	for (int i = 0; i < static_cast<int>(v.size()); i++) {
	if (!first) {
		res += ", ";
	}
	first = false;
	res += to_string(v[i]);
	}
	res += "}";
	return res;
}
 
template <size_t N>
string to_string(bitset<N> v) {
	string res = "";
	for (size_t i = 0; i < N; i++) {
		res += static_cast<char>('0' + v[i]);
	}
	return res;
}
 
template <typename A>
string to_string(A v) {
	bool first = true;
	string res = "{";
	for (const auto &x : v) {
		if (!first) {
			res += ", ";
		}
		first = false;
		res += to_string(x);
	}
	res += "}";
	return res;
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
	return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
	return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
	return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	cerr << " " << to_string(H);
	debug_out(T...);
}

void Clearing_out() { return; }

template <typename Head, typename... Tail>
void Clearing_out(Head &H, Tail & ... T) {
	H.clear();
	Clearing_out(T...);
}

void testcase(){
//	int dp[50][50];
	int h, w;
	cin >> h >> w;
	string grid[h];
	for(int i = 0; i < h; i++){
		cin >> grid[i];
	}
	int ans = 1;
	const int mod = 998244353;
	for(int col = 0; col < w; col++){
		int nr= 0, nb =0, nd = 0;
		int j = col;
		int i = 0;
		while(j >= 0 && i < h){
			if(grid[i][j] == '.')nd++;
			else if(grid[i][j] == 'R')nr++;
			else nb++;
			j--, i++;
		}
		if(nr > 0 && nb > 0){
			
			cout << "0";
			return;
		}
		else if(nr > 0) ans *= 1;
		else if(nb > 0) ans *= 1;
		else ans *= 2, ans %= mod;
	}
	for(int row = 1; row < h; row++){
		int nr= 0, nb =0, nd = 0;
		int i = row;
		int j = w-1;
		while(i < h && j>= 0){
			if(grid[i][j] == '.')nd++;
			else if(grid[i][j] == 'R')nr++;
			else nb++;
			j--, i++;
		}
		if(nr > 0 && nb > 0){
			
			cout << "0";
			return;
		}
		else if(nr > 0) ans *= 1;
		else if(nb > 0) ans *= 1;
		else ans *= 2, ans %= mod;
	}
	cout << ans << '\n';
}


int32_t main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int tt = 1;
//	cin >> tt;
	while(tt--){
		testcase();
	}
	return 0;
}
