#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fast_IO ios::sync_with_stdio(false);
#define DEBUG fprintf(stderr,"Running on Line %d in Function %s\n",__LINE__,__FUNCTION__)
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define fir first
#define sec second
#define mod 998244353
#define ll long long
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
inline int read()
{
	char ch=getchar(); int nega=1; while(!isdigit(ch)) {if(ch=='-') nega=-1; ch=getchar();}
	int ans=0; while(isdigit(ch)) {ans=ans*10+ch-48;ch=getchar();}
	if(nega==-1) return -ans;
	return ans;
}
typedef pair<int,int> pii;
void print(vector<int> x){for(int i=0;i<(int)x.size();i++) printf("%d%c",x[i]," \n"[i==(int)x.size()-1]);}
inline int add(int x,int y) {return x+y>=mod?x+y-mod:x+y;}
inline int add(int x,int y,int z) {return add(add(x,y),z);}
inline int sub(int x,int y) {return x-y<0?x-y+mod:x-y;}
inline int mul(int x,int y) {return 1LL*x*y%mod;}
inline int mul(int x,int y,int z) {return mul(mul(x,y),z);}
#define N 505
char s[N][N];
int n,m,ans=1;
signed main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++) scanf("%s",s[i]+1);
	for(int i=1;i<=n;i++)
	{
		int col=0;
		for(int j=1;j<=i;j++)
		{
			if(s[i-j+1][j]=='B')
			{
				if(!col) col=1;
				if(col==2) col=-1;
			}
			else if(s[i-j+1][j]=='R')
			{
				if(!col) col=2;
				if(col==1) col=-1;
			}
		}
		if(col==-1) ans=0;
		if(col==0) ans=add(ans,ans);
	}
	for(int i=2;i<=m;i++)
	{
		int col=0;
		for(int j=i;j<=m;j++)
		{
			if(n-(j-i)<=0) continue;
			char ch=s[n-(j-i)][j];
			if(ch=='B')
			{
				if(!col) col=1;
				if(col==2) col=-1;
			}
			else if(ch=='R')
			{
				if(!col) col=2;
				if(col==1) col=-1;
			}
		}
		if(col==-1) ans=0;
		if(col==0) ans=add(ans,ans);
	}
	cout<<ans<<endl;
	return 0;
}



/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author NikuKyabe
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define REV(i, a, b) for (int i = (b) - 1; i >= (a); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001l
#define MOD 1000000007
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class CMaxGCD2 {
public:
    /**
     * 約数全列挙
     * @param n 約数を求める数
     * @return 約数を昇順に並べたvector
     */
    vector<int> all_factor(int n){
        vector<int> ret;
        for(int i = 1; i * i <= n; i++){
            if(n % i == 0){
                ret.push_back(i);
                //iが約数の時，n/iも約数
                //i * i == nの時は重複する為加えない
                if(i * i != n) ret.push_back(n / i);
            }
        }
        sort(ret.begin(), ret.end());
        return ret;
    }
	void solve(std::istream& cin, std::ostream& cout) {
        int a,b;
        cin >> a >> b;
        map<int, int> memo;
        FOR(i, a, b+1){
            auto aa = all_factor(i);
            for(auto j : aa){
                memo[j]++;
            }
        }
        int ans = 1;
        for(auto itr = memo.begin(); itr != memo.end(); itr++){
            if(itr->second > 1){
                ans = max(ans, itr->first);
            }
        }
        cout << ans << endl;
	}
};

signed main() {
	CMaxGCD2 solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}
