#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using pl = pair<ll, ll>;
constexpr int MX = 5005, MOD = 998244353;

pl DP[MX][2];

int main() {
	if (fopen("in", "r")) freopen("in", "r", stdin), freopen("out", "w", stdout);
	cin.tie(0)->sync_with_stdio(0);

	int N, M; cin >> N >> M;
	ll ans = 0;
	for (int i = 1; i <= M; ++i) {
		DP[0][0] = pl(0, M-1), DP[0][1] = pl(1, 1);
		for (int j = 0; j < N-1; ++j) {
			DP[j+1][0] = pl((M-1)*DP[j][0].f+(i-1)*DP[j][1].f, (M-1)*DP[j][0].s+(i-1)*DP[j][1].s);
			DP[j+1][1] = pl(DP[j][0].f+DP[j][0].s+(M-i+1)*DP[j][1].f, DP[j][0].s+(M-i+1)*DP[j][1].s);
			DP[j+1][0].f %= MOD, DP[j+1][0].s %= MOD;
			DP[j+1][1].f %= MOD, DP[j+1][1].s %= MOD;
		}
		(ans += DP[N-1][0].f+DP[N-1][1].f) %= MOD;
	}
	cout << ans;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll z = 0;

int main(){
  ll H, W;
  cin >> H >> W;
  
  vector<vector<char>> S(H + 1, vector<char>(W + 1));
  for (ll i = 1; i <= H; i++){
    for (ll j = 1; j <= W; j++){
      cin >> S[i][j];
    }
  }
  
  vector<vector<ll>> Wtate(H + 1, vector<ll>(W + 1)), Wyoko(H + 1, vector<ll>(W + 1)), Wnaname(H + 1, vector<ll>(W + 1));
  for (ll i = 1; i <= H; i++){
    ll now = 0;
    for (ll j = 1; j <= W; j++){
      if (S[i][j] == '#'){
        now = j;
      }
      
      Wtate[i][j] = now;
    }
  }
  for (ll j = 1; j <= W; j++){
    ll now = 0;
    for (ll i = 1; i <= H; i++){
      if (S[i][j] == '#'){
        now = i;
      }
      
      Wyoko[i][j] = now;
    }
  }
  for (ll i = H; i > 0; i--){
    ll now = 0;
    for (ll j = 1; j <= W; j++){
      if (i + j > H || j > W){
        break;
      }
      
      if (S[i + j][j] == '#'){
        now = j;
      }
      
      Wtate[i + j][j] = now;
    }
  }
  for (ll j = 2; j <= W; j++){
    ll now = 0;
    for (ll i = 1; i <= H; i++){
      if (i + j > W || i > H){
        break;
      }
      
      if (S[i][i + j] == '#'){
        now = i;
      }
      
      Wtate[i][i + j] = now;
    }
  }
  
  vector<vector<ll>> ruitate(H + 1, vector<ll>(W + 1, 0)), ruiyoko(H + 1, vector<ll>(W + 1, 0)), ruinaname(H + 1, vector<ll>(W + 1, 0)), ans(H + 1, vector<ll>(W + 1, 0));
  for (ll i = 1; i <= H; i++){
    for (ll j = 1; j <= W; j++){
      if (i == 1 && j == 1){
        ruitate[i][j] = 1;
        ruiyoko[i][j] = 1;
        ruinaname[i][j] = 1;
        ans[i][j] = 1;
        continue;
      }
      
      if (S[i][j] == '.'){
        ans[i][j] += ruitate[max(z, i - 1)][j];
        ans[i][j] += ruiyoko[i][max(z, j - 1)];
        ans[i][j] += ruinaname[max(z, i - 1)][max(z, j - 1)];
        
        ans[i][j] %= 1000000007;
        ruitate[i][j] = (ans[i][j] + ruitate[max(z, i - 1)][j]) % 1000000007;
        ruiyoko[i][j] = (ans[i][j] + ruiyoko[i][max(z, j - 1)]) % 1000000007;
        ruinaname[i][j] = (ans[i][j] + ruinaname[max(z, i - 1)][max(z, j - 1)]) % 1000000007;
      }
    }
  }
  
  cout << ans[H][W] << endl;
}