#include<bits/stdc++.h>
#define ll long long
#define inf 0x3f3f3f3f
using namespace std;
const ll mod = 1e9+7;
const int maxn = 2005;
char s[2005][2005];
ll qpow(ll a,ll b){
	ll res=1ll;
	while(b){
		if(b&1)res=res*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return res;
}
int n,m;
ll c[maxn],l[maxn],nn[maxn][maxn];
int main() {
	for(int i=0;i<maxn;i++)
        for(int j=0;j<maxn;j++)
        s[i][j]='#';
	ll p = 0;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++){
		scanf("%s",s[i]+1);
		for(int j=1;j<=m;j++){
			if(s[i][j]=='.')p++;
		}
	}
	memset(nn,0,sizeof(nn));
	for(int i=1;i<=n;i++){
		for(int j=0;j<=m+1;j++)c[j]=0;
		for(int j=1;j<=m;j++){
			if(s[i][j]=='.'){
				c[j]=c[j-1]+1;;
			}else{
				c[j]=0;
			}
		}
		for(int j=m;j>0;j--){
			if(c[j]!=0){
				c[j]=max(c[j],c[j+1]);
			}
		}
		for(int j=1;j<=m;j++){
			nn[i][j]=c[j];
		}
	}
	for(int i=1;i<=m;i++){
		for(int j=0;j<=n+1;j++)c[j]=0;
		for(int j=1;j<=n;j++){
			if(s[j][i]=='.'){
				c[j]=c[j-1]+1;;
			}else{
				c[j]=0;
			}
		}
		for(int j=n;j>0;j--){
			if(c[j]!=0){
				c[j]=max(c[j],c[j+1]);
			}
		}
		for(int j=1;j<=n;j++){
			nn[j][i]+=c[j];
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(nn[i][j]!=0){
				nn[i][j]--;
			}
		}
	}
	ll ans = 0;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(s[i][j]=='.'){
				ll k=nn[i][j];
				ll tmp = ((qpow(2ll,k)-1ll+mod)%mod)*(qpow(2ll,p-k))%mod;
				ans=(ans+tmp)%mod;
			}
		}
	}
	printf("%lld",ans);
	return 0;
}

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
#define pb push_back
#define F first
#define S second
int d[200005];
int sz[200005];
int fi(int x) {
    if (d[x] == x) {
        return x;
    }
    else {
        return d[x] = fi(d[x]);
    }
    //return d[x] == x ? x : d[x] = fi(d[x]);
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    int a[n+5];
    for (int i = 1 ; i <= n ; i++) {
        cin >> a[i];
    }
    for (int i = 1 ; i <= 200000 ; i++) {
        d[i] = i;
        sz[i] = 1;
    }
    for (int i = 1 ; i <= n / 2 ; i++) {
        if (a[i] != a[n+1-i]) {
            int x = fi(a[i]);
            int y = fi(a[n+1-i]);
            if (x != y) {
                sz[y] += sz[x];
                d[x] = y;
            }
        }
    }
    int ans = 0;
    for (int i = 1 ; i <= 200000 ; i++) {
        if (d[i] == i) {
            ans += sz[i] - 1;
        }
    }
    cout << ans << '\n';
}
