#include <bits/stdc++.h>
using namespace std;

#define dbg(v) cout << __LINE__ << ": " << #v << " = " << v << endl

const int N = 2e3 + 5;
const int M = 1e9 + 7;

char str[N];

int add (int a, int b) {
    return (a + b < M) ? (a + b) : (a + b - M);
}

int main() {
    int h, w;
    scanf("%d %d", &h, &w);
    vector <string> s(h);
    for (string &v : s) {
        scanf(" %s", str);
        v = str;
    }
    vector <int> r(h), c(w), d(h + w);
    int ans = 0;
    for (int i = h - 1; i >= 0; i--) {
        for (int j = w - 1; j >= 0; j--) {
            if (i == h - 1 and j == w - 1) {
                r[i] = 1;
                c[j] = 1;
                d[i - j + w] = 1;
                continue;
            }
            if (s[i][j] == '#') {
                r[i] = c[j] = d[i - j + w] = 0;
            }
            else {
                ans = 0;
                ans = add(ans, r[i]);
                ans = add(ans, c[j]);
                ans = add(ans, d[i - j + w]);
                r[i] = add(r[i], ans);
                c[j] = add(c[j], ans);
                d[i - j + w] = add(d[i - j + w], ans);
            }
        }
    }
    printf("%d\n", ans);
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define flush cout.flush

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pl = pair<ll, ll>;
const ll INF = 1e9 + 7;
const ll mod = 1e9 + 7;
const ll mod2 = 998244353;
const ld eps = 1e-9;
const ld PI = acos(-1);

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, m;
    cin >> n >> m;
    vector<vector<char>> mx(n, vector<char>(m));
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            cin >> mx[i][j];
        }
    }
    ll res = 1;
    for (int i = 0; i < n + m - 1; ++i) {
        bool red = false, blue = false;
        for (int j = 0; j < m; ++j) {
            if (i - j < 0)continue;
            if (i - j >= n)continue;
            if (mx[i - j][j] == 'R') {
                red = true;
            }
            if (mx[i - j][j] == 'B') {
                blue = true;
            }
        }
        if (red && blue) {
            cout << 0 << "\n";
            return 0;
        }
        if (!red && !blue) {
            res *= 2;
            res %= mod2;
        }
    }
    cout << res << "\n";
    return 0;
}