//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimization("unroll-loops")
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
template<class T> using indexed_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
const int N=2e6+7;
const int mod=1e9+7;
const int INF=1e18+7;
const double EPS=1e-12;
const int dx[]={-1,1,0,0}; // UDLR
const int dy[]={0,0,-1,1}; // UDLR
inline int maximum(int a,int b) {int c=a>b?a:b; return c;}
inline int minimum(int a,int b) {int c=a>b?b:a; return c;}


int32_t main(){
    cin.tie(nullptr)->sync_with_stdio(false);

    int a,b; cin>>a>>b;
    a+=b;
    if(a>=15&&b>=8) cout<<"1"<<'\n';
    else if(a>=10&&b>=3) cout<<"2"<<'\n';
    else if(a>=3) cout<<"3"<<'\n';
    else cout<<"4"<<'\n';

 return 0;
}

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
#include<bits/stdc++.h>
    //#include <unordered_set>
    //#include <unordered_map>

using namespace std;


const double pi = 3.141592653689793238460;
const long long inf = 0x3f3f3f3f;
const int   N = 2e5 + 5;
const int pr = 31;
#define ll long long 
using ld = long double;
#define vi vector<int> 
#define pb push_back
#define mp make_pair
#define MEM(x) memset(x,0,sizeof(x))
#define fi first
#define se second
#define forn(i, n) for (int i = 0; i< n; i++)
#define forl(i,l,u) for(int i=(int)l;i<=(int)u;++i)
#define all(v) (v).begin(), (v).end()
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
int mod = 998244353;

int gcd(int a, int b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}
int power(long long x, unsigned int y, int p)
{   //(x^y)%p 
    int res = 1;
    x = x % p;
    if (x == 0) return 0;

    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    //#define int ll
    //cout << fixed << setprecision(17);
    
    ll m = 998244353;
    int h, w;
    cin >> h >> w;
    string s[10005];
    forn(i, h) {
        cin >> s[i];
    }
    ll ways = 1LL;
    vector<char> a[10005];
    forn(i, h) {
        forn(j, w) {
            a[i + j].pb(s[i][j]);
        }
    }
    int to = h + w - 2;
    int pow = 0;
    forl(i, 0, to) {
        int r = 0;
        int b = 0;
        forn(j, (int)a[i].size()) {
            if (a[i][j] == 'R') {
                r++;
            }
            if(a[i][j] == 'B')b++;
        }
        if (r == 0 && b == 0) {
            pow++;
        }
        else {
            if (r > 0 && b > 0) {
                cout << 0 << endl;
                return 0;
            }
        }
    }
    cout << power(2,pow,m) << endl;
}


