#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;

int main()
{
    int h, w;
    cin >> h >> w;

    vector<string> s(h);
    rep (i, h)
        cin >> s[i];

    int ans = 0;
    rep (i, h)
        rep (j, w)
        {
            if (j + 1 < w && s[i][j] == '.' && s[i][j + 1] == '.')
                ans++;
            if (i + 1 < h && s[i][j] == '.' && s[i + 1][j] == '.')
                ans++;
        }

    cout << ans << endl;
    return 0;
}

#include <bits/stdc++.h>
#define LL long long
#define LD long double
#define MAXN
#define MAXM
#define P 998244353
#define MP make_pair
#define PB push_back
#define INF 0x3f3f3f3f
#define dbg(a...) fprintf(stderr, a)
using namespace std;

int h, w, ans=1;
char mp[505][505];
int main()
{
    scanf("%d%d", &h, &w);
    for(int i=1; i<=h; ++i) {
        scanf("%s", mp[i]+1);
    }
    for(int i=2; i<=h+w; ++i) {
        int flag=0;
        for(int j=1; j<i; ++j) {
            int x=j, y=i-j;
            if(x>h || y>w) continue;
            if(mp[x][y]=='B') {
                if(flag==2) ans=0;
                else flag=1;
            }
            if(mp[x][y]=='R') {
                if(flag==1) ans=0;
                else flag=2;
            }
            //printf("%d %d %d\n", x, y, flag);
        }
        if(flag==0) ans=ans*2%P;
    }
    printf("%d\n", ans);
    return 0;
}