#include <bits/stdc++.h>
#define F first
#define S second
#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define per(i, a, b) for(int i = (b)-1; i >= (a); --i)
#define bck(i, a, b) if ((i) >= (a) && (i) < (b))
#define trav(x, a) for (auto &x : (a))
#define sz(a) (int)(a).size()
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define dbg(X) std::cerr << "[DBG]("<<__FUNCTION__<<":"<<__LINE__<<") " << #X << ": " << X << std::endl;
using namespace std;
typedef long long ll;
typedef string str;
template<typename T> using vec = vector<T>;
template<typename T> using pq = priority_queue<T, vector<T>, std::greater<T>>;
template<typename T> using mxpq = priority_queue<T>;
typedef pair<int,int> pii;
typedef vec<int> vi;
typedef vec<pii> vii;
typedef vec<vi> vvi;
typedef pair<ll,ll> pll;
typedef vec<ll> vl;
typedef vec<pll> vll;
typedef vec<vl> vvl;
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
template<typename A, typename B>
istream& operator>>(istream& s, pair<A,B>& p) { return s>>p.first>>p.second; }
template<typename T>
istream& operator>>(istream& s, vec<T>& p) {
    for (T& t : p) s >> t;
    return s;
}

#define MOD 1000000007ll

ll modpow(ll b, ll e, ll mod=MOD) {
    if (e < 0) return modpow(modpow(b, mod-2, mod), -e, mod);
    ll r = 1;
    while (e) {
        if (e & 1) r = r*b % mod;
        b = b*b % mod;
        e /= 2;
    }
    return r;
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int h, w; cin >> h >> w;
    vec<str> g(h); cin >> g;
    vi _gg(w*h);
    auto& gg = *(int (*)[h][w]) &_gg[0];
    rep(i, 0, h) {
        int l=0;
        rep(j, 0, w) {
            if (g[i][j] == '#') {
                rep(k, l, j) gg[i][k] = j-l;
                l = j+1;
            }
        }
        rep(k, l, w) gg[i][k] = w-l;
    }
    rep(j, 0, w) {
        int l=0;
        rep(i, 0, h) {
            if (g[i][j] == '#') {
                rep(k, l, i) gg[k][j] += i-l-1;
                l = i+1;
            }
        }
        rep(k, l, h) gg[k][j] += h-l-1;
    }
    ll k = 0;
    trav(v, g) trav(c, v) k += c=='.';
    ll s = 0;
    vl p2(k+1, 1); rep(i,1,k+1) p2[i] = 2*p2[i-1] % MOD;
    rep(i,0,h) rep(j,0,w)
        (s += p2[k] - p2[k-gg[i][j]] + MOD) %= MOD;
    cout << s << endl;
}

#include<bits/stdc++.h>
#define ll long long
#define mod 998244353
using namespace std;
int n,m;
int mul[5009][5009];
int sm[5009][5009];
void init()
{
	for(int i=0;i<=m;i++)
	{
		mul[i][0]=1;
		for(int j=1;j<=n;j++)
		{
			mul[i][j]=(ll)mul[i][j-1]*i%mod;
			// printf("i:%d j:%d mul:%d\n",i,j,mul[i][j]);
		}
	}
	memcpy(sm,mul,sizeof(sm));
	for(int j=0;j<=n;j++)
		for(int i=1;i<=m;i++)
		{
			(sm[i][j]+=sm[i-1][j])%=mod;
			// printf("i:%d j:%d sm:%d\n",i,j,sm[i][j]);
		}
}
void solve()
{
	int ans=(ll)mul[m][n]*n%mod;
	int rv=0;
	for(int i=2;i<=n;i++)
	{
		for(int j=1;j<=i-1;j++)
		{
			// int tm=(ll)sm[m-1][i-j-1]*mul[m][j-1]%mod;
			// printf("i:%d j:%d tm:%d\n",i,j,tm);
			rv=(rv+(ll)sm[m-1][i-j-1]*mul[m][j-1]%mod*mul[m][n-i])%mod;
		}
	}
	ans=(ans-rv+mod)%mod;
	printf("%d",ans);
}
int qpow(int a,int b)
{
	int ans=1;
	for(;b;b>>=1,a=(ll)a*a%mod)
		if(b&1)
			ans=(ll)ans*a%mod;
	return ans;
}
int main()
{
	scanf("%d%d",&n,&m);
	init();
	solve();
	return 0;
}