#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("O2")

#include"bits/stdc++.h"
using namespace std;
const int p = 31;
const int M = 998244353;
typedef long long ll;
typedef double d;
typedef long double ld;
typedef unsigned long long ull;
#define ar array
#define ff first
#define ss second
#define vt vector
mt19937_64 rnd(time(NULL));
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
ll euclid(ll a, ll b, ll &x, ll &y) {if (!b) return x = 1, y = 0, a; ll d = euclid(b, a % b, y, x); return y -= (a / b) * x, d;}

int main() {

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int l, r;
    cin >> l >> r;
    ll ans = 0ll;
    if (l == r) {
        cout << 0;
        return 0;
    }
    vector<ll>pf(r + 3);
    for (int i = r + 1; i >= 2; --i) {
        ll dif = (r / i - (l + i - 1) / i + 1);
        pf[i] = dif*dif;
        ll now = 2 * i;
        for (; now <= r; now += i) {
            pf[i] -= pf[now];
        }
    }
    for(int i=2;i<=r;++i){
        ans+=pf[i];
        if(i>=l){
            ans-=2*((r / i - (l + i - 1) / i + 1));
            ans+=1;
        }
    }
    cout<<ans<<'\n';
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n"; //check time
    return 0;
}

#include <bits/stdc++.h>
#define ff first
#define ss second
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define pii pair<int, int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define sws ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl '\n'
#define teto(a, b) ((a+b-1)/(b))
using namespace std;

// Extra
#define forn(i, n) for(int i = 0; i < (int)n; i++)
#define forne(i, a, b) for(int i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
#define dbg(msg, var) cout << msg << " " << var << endl;
//

const int MAX = 200010;
const ll MOD = (int) 998244353;
const int INF = 1e9;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
const ld EPS = 1e-8;

int32_t main() {
    // sws;
    int n, m;
    cin >> n >> m;

    vector<vector<char>> mat(n, vector<char>(m, 0));
    vi qtr(n+m+10), qtb(n+m+10), qtp(n+m+10);

    ll res = 1;

    forn(i, n) {
        forn(j, m) {
            cin >> mat[i][j];
            int d = i+j;
            if(mat[i][j] == 'R')
                qtr[d]++;
            if(mat[i][j] == 'B')
                qtb[d]++;
            if(mat[i][j] == '.')
                qtp[d]++;
        }
    }

    forn(d, n+m-1) {
        if(qtr[d] and qtb[d]) {
            res = 0;
            break;
        }
        if(!qtr[d] and !qtb[d]) {
            res = (res + res) % MOD;
        }
    }

    cout << res << endl;



    // int overflow, array bounds special cases (n=1?)
    // do smth instead of nothing and stay organized - divide in subproblems?
    // WRITE STUFF DOWN DON'T GET STUCK ON ONE APPROACH
    return 0;
}
