#include <bits/stdc++.h>

#define ln                 '\n'
#define all(dat)           dat.begin(), dat.end()
#define loop(i, to)        for (int i = 0; i < to; ++i)
#define cont(i, to)        for (int i = 1; i <= to; ++i)
#define circ(i, fm, to)    for (int i = fm; i <= to; ++i)
#define foreach(i, dat)    for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long          num;

using namespace std;

template<int mod> struct modulo {
	typedef modulo T;
	int w;
	operator int() const { return w; }
	
	modulo() {}
	modulo(int w) { this->w = w; fix(); }
	template<class A> modulo(A w) { this->w = w % mod; fix(); }
	inline void fix() { if (w >= mod || w < -mod) w %= mod; if (w < 0) w += mod; }
	
	inline T  operator -  () const { return mod - w; }
	inline T& operator += (const T &b) { if ((w += b.w) >= mod) w -= mod; return *this; }
	inline T& operator -= (const T &b) { if ((w -= b.w) < 0) w += mod; return *this; }
	inline T& operator *= (const T &b) { w = (unsigned long long) w * b.w % mod; return *this; }
	inline T& operator /= (const T &b) { return *this *= b.inv(); }
	#define make_operation(P)\
	friend inline T operator P (const T &a, const T &b) { return T(a) P##= b; }\
	template<class U> friend inline T operator P (const T &a, const U &b) { return T(a) P##= b; }\
	template<class U> friend inline T operator P (const U &a, const T &b) { return T(a) P##= b; }
	make_operation(+) make_operation(-) make_operation(*) make_operation(/)
	#undef make_operation
	
	inline T inv() const {
		int a = w, m = mod, u = 0, v = 1, t;
		for (; a != 0; t = m / a, m -= t * a, swap(a, m), u -= t * v, swap(u, v));
		return u;
	}
	
	friend inline T pow(const T &w, num p) {
		T a = w, r = 1; for (; p > 0; a *= a, p >>= 1) if (p & 1) r *= a; return r;
	}
};
const int mod = 998244353;
typedef modulo<mod> rem;

const int nsz = 5e2;
char s[nsz + 5][nsz + 5];
int n, m, d[2 * nsz + 5];
rem ans = 1;

int main() {
	scanf("%d%d", &n, &m);
	cont (i, n) scanf("%s", s[i] + 1);
	cont (i, n + m - 1) d[i] = -2;
	cont (i, n) cont (j, m) if (s[i][j] != '.') {
		int id = i + j - 1, c = s[i][j] == 'R' ? 0 : 1;
		if (d[id] == -2) d[id] = c;
		else if (d[id] != c) d[id] = -1;
	}
	cont (i, n + m - 1) {
		if (d[i] == -1) ans = 0;
		else if (d[i] == -2) ans *= 2;
	}
	printf("%d\n", ans.w);
}
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define ALL(x) (x).begin(),(x).end()
template<class T>bool umax(T &a, const T &b) {if(a<b){a=b;return 1;}return 0;}
template<class T>bool umin(T &a, const T &b) {if(b<a){a=b;return 1;}return 0;}
#ifdef LOCAL
void _debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void _debug_out(Head H, Tail... T) { cerr << " " << to_string(H); _debug_out(T...); }
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", _debug_out(__VA_ARGS__)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...) 42
#define eprintf(...) 42
#endif

bool chikai(ll a,ll b,ll c,ll d) {
  return abs(a-c)+abs(b-d) <= 3;
}

ll r1, c1, r2, c2;

ll solve() {
  if(r1==r2 && c1==c2)  return 0; 

  {
    ll tasu1 = r1+c1;
    ll tasu2 = r2+c2;
    ll hiku1 = r1-c1;
    ll hiku2 = r2-c2;

    if(chikai(r1,c1,r2,c2)) return 1;
    if(tasu1==tasu2) return 1;
    if(hiku1==hiku2) return 1;

    if((tasu1 %2) == (tasu2%2)) return 2;
    if((hiku1 %2) == (hiku2%2)) return 2;
  }

  rep(x,-3,4) rep(y,-3,4) {
    if(abs(x)+abs(y)>3) continue;
    ll rr1 = r1+x;
    ll cc1 = c1+y;

    ll tasu1 = rr1+cc1;
    ll tasu2 = r2+c2;
    ll hiku1 = rr1-cc1;
    ll hiku2 = r2-c2;

    if(chikai(rr1,cc1,r2,c2)) return 2;
    if(tasu1==tasu2) return 2;
    if(hiku1==hiku2) return 2;
  }
  rep(x,-3,4) rep(y,-3,4) {
    if(abs(x)+abs(y)>3) continue;
    if(x+y>3) continue;
    ll rr2 = r2+x;
    ll cc2 = c2+y;

    ll tasu1 = r1+c1;
    ll tasu2 = rr2+cc2;
    ll hiku1 = r1-c1;
    ll hiku2 = rr2-cc2;

    if(chikai(r1,c1,rr2,cc2)) return 2;
    if(tasu1==tasu2) return 2;
    if(hiku1==hiku2) return 2;
  }


  return 3;
}

int main() {
  cin >>  r1 >> c1 >> r2 >> c2;
  cout << solve() <<endl;
}
