#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;
const int maxn=1e3+5;
int a[maxn],b[maxn];
int book1[maxn],book2[maxn];
int main()
{
	int n,m;
	scanf("%d %d",&n,&m);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		book1[a[i]]=1;
	}
		
	for(int i=1;i<=m;i++)
	{
		scanf("%d",&b[i]);
		book2[b[i]]=1;
	}
	for(int i=1;i<=1000;i++)
	{
		if((book1[i]==1 && book2[i]!=1) || (book1[i]!=1 && book2[i]==1))
			printf("%d ",i);
	}
	printf("\n");
}

//#include<bits/stdc++.h> ----万能头----
#include <iostream>
#include<stdio.h>
#include<string>
#include<algorithm>
#include<string.h>
#include<cstring>
#include<cmath>
#include<queue>
#include<list>
#include<map>
#include<set>
#include<unordered_map>
#include<stack>
#include<time.h>
using namespace std;
const int mod = 1e9+7;
const int N = 2e3+5;
const int maxn = 1e5+5;
const long long INF =1e18;
#define REP(i,n) for(int i = 1; i <= n; ++i)
#define REPA(i,j,n) for(ll i = j; i <= n; ++i)
#define RREP(i,n) for(ll i = n; i >= 1; --i)
#define REPR(i,j,n) for(ll i = n; i >= j; --i)
#define lll __int128
#define Accpect return 0;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<double,ll> pdi;
int t;
ll n, m;
ll a[N];
inline int read(){
    char c=getchar();
    int x=0,f=1;
    while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
    while(isdigit(c))x=(x<<3)+(x<<1)+(c^48),c=getchar();
    return x*f;
}
const int MOD = 998244353;
char g[503][503];
ll fast(ll a,ll b){
    ll res = 1;
    while(b){
        if(b & 1)res = res * a % MOD;
        a = a * a % MOD;
        b >>= 1;
    }
    return res % MOD;
}
void solve(){
    ll w, h;
    cin>>h>>w;
    ll ans = 0;
    bool f = 1;
    for(int i = 1; i <= h; ++i)cin>>g[i]+1;
    for(int i  = 2 ; f && i <= w; ++i){
        int x = 1, y = i;
        int c1 = 0, c2 = 0;
        while(x <= h && y >= 1){
            if(g[x][y] == 'R')++c1;
            else if(g[x][y] == 'B')++c2;
            if(c1 && c2){
                f = 0;break;
            }
            ++x, --y;
        }
        if(!c1 && !c2) ++ans;
    }
    for(int i = 2; f && i < h ; ++i){
        int x = i , y = w;
        int c1 = 0, c2 = 0;
        while(y >= 1 && x <= h){
            if(g[x][y] == 'R')++c1;
            else if(g[x][y] == 'B')++c2;
            if(c1 && c2){
                f = 0;break;
            }
            --y,++x;
        }
        if(!c1 && !c2)++ans;
    }
    if(!f) cout<<0<<'\n';
    else {
        if(g[1][1] == '.')++ans;
        if(g[h][w] == '.')++ans;
        cout<<fast(2,ans)<<'\n';
    }
}

signed main(){
    //ios::sync_with_stdio(0);
    //cin.tie(0);
    //.cout.tie(0);
#ifdef ACM
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    t = 1;

    //srand((unsigned)time(NULL));
//    cin>>t;

    while (t--){

        solve();

    }

    fclose(stdin);
    fclose(stdout);
    //-------------
    Accpect;
    //-------------
}

