#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll MOD=1e9+7;

ll exp(ll a,ll n){
    if(n==0)    return 1;
    if(n==1)    return a;
    ll ans=exp(a,n/2);
    ans*=ans;ans%=MOD;
    if(n&1) ans*=a,ans%=MOD;
    return ans;
}

void solve(){
    int n,m;cin>>n>>m;
    string s[n];
    for(int i=0;i<n;i++)    cin>>s[i];

    int top[n][m],bottom[n][m],left[n][m],right[n][m];
    memset(top,0,sizeof(top));
    memset(bottom,0,sizeof(bottom));
    memset(left,0,sizeof(left));
    memset(right,0,sizeof(right));

    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            if(s[i][j]=='#')    continue;
            top[i][j]=1;
            if(i)   top[i][j]+=top[i-1][j];
        }
    }
    for(int i=n-1;i>=0;i--){
        for(int j=0;j<m;j++){
            if(s[i][j]=='#')    continue;
            bottom[i][j]=1;
            if(i+1<n)   bottom[i][j]+=bottom[i+1][j];
        }
    }

    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            if(s[i][j]=='#')    continue;
            left[i][j]=1;
            if(j)   left[i][j]+=left[i][j-1];
        }
    }
    for(int i=0;i<n;i++){
        for(int j=m-1;j>=0;j--){
            if(s[i][j]=='#')    continue;
            right[i][j]=1;
            if(j+1<m)   right[i][j]+=right[i][j+1];
        }
    }

    int nTidy=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            if(s[i][j]=='.')    nTidy++;
        }
    }
    ll total=exp(2,nTidy)*nTidy%MOD;
    ll negativeContri=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            if(s[i][j]=='#')    continue;
            int restriction=top[i][j]+bottom[i][j]+left[i][j]+right[i][j]-4+1;
            negativeContri+=exp(2,nTidy-restriction);
            negativeContri%=MOD;
        }
    }
    cout<<(total-negativeContri+MOD)%MOD<<"\n";
}

main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    #ifndef ONLINE_JUDGE    
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout); 
    #endif
    solve();
}
//x<<y=x*2^y,x>>y=x/2^y
//1e5+3 is prime
// in a matrix, all elements of a primary diagonal have constant diff of coordinates
// and a secondary diagonal has constant sum of coordinates
//use ll() for using an integer in self-built fn
//(x&-x) bitwise and of (x and its 2's complement) returns (last set bit)
//eg if x=1010 then it will return 0010 
// careful dont print empty container(run time error) 
//v.erase O(n)
//use ("\n") instead of endl as endl flushes the output buffer
//every time so takes more time than \n (TLE)
//stoll() and to_string((less than 1e19))
//INT_MAX is approx 3e10
//For sets use set_name.lower_bound(x)(strictly O(logn)) 
//NOT lb(all(s),x)(O(logn) for random access (eg vector) but for sets it is O(n));
#include<bits/stdc++.h>
typedef long long int ll;
#define ull unsigned long long int
#define lld long double
#define endl "\n"
#define fi first 
#define sec second 
#define sp setprecision 
#define lb lower_bound
#define ub upper_bound
#define For(i, a, b) for(long long int i = (a); i <= (b); i++)
#define Forr(i, a, b) for(long long int i = (a); i >= (b); i--)
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define vll vector<ll>
#define pll pair<ll,ll>
#define vlld vector<lld>
#define vi vector<int>
#define vch vector<char>
#define sll set<ll>
#define sch set<ch>
#define vpll vector< pair<ll,ll> >
#define vpii vector< pair<int,int> >
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mll map<ll, ll>
#define mcll map<char,ll>
#define sz(container) ll((container).size())
#define fill(a,b) memset(a, b, sizeof(a))
#define fast_io ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
using namespace std;
lld pi=3.1415926535897932;
const ll mod=998244353;
const ll dx[4]={-1, 0, 1, 0} , dy[4]={0, 1, 0, -1};
const ll dxx[8]={-1, -1, 0, 1, 1, 1, 0, -1} , dyy[8]={0, 1, 1, 1, 0, -1, -1, -1};
string ds="RLDU";
/***************************************
struct cmp 
{
    bool operator() (const pll &a, const pll &b)  const 
    {
        ll lena = a.sec - a.fi + 1;
        ll lenb = b.sec - b.fi + 1;
        if (lena == lenb) return a.fi < b.fi;
        return lena > lenb;
    }
};
********************************/



ll lcm(ll a, ll b)
{
    ll g=__gcd(a, b);
    return a/g*b;
}

ll binpow(ll a, ll b,ll m) 
{
    a %= m;
    ll res = 1;
    while (b > 0) 
    {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
ll modinv(ll n) 
{
    return binpow(n, mod - 2,mod);
}

/**************coding*********************/
vector<vll >adj(105);
vll used(105,0);
void dfs(ll v) 
{
    used[v]=1;
    for(ll u : adj[v]) 
    {
        if (!used[u]) dfs(u);
    }
}  
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    fast_io;
    ll T=1;//cin>>T;
    For(i,1,T)
    {
        ll n;cin>>n;
        string s[n];
        For(j,0,n-1) cin>>s[j];
        For(j,0,n-1)
        {
            For(k,0,n-1)
            {
                if(s[j][k]=='1') adj[j].pb(k);
            }
        }
        lld ans=0;
        vll vis(n,0);
        For(j,0,n-1)
        {
            For(k,0,n-1) used[k]=0;
            dfs(j);
            For(k,0,n-1) if(used[k]==1) vis[k]++;
        }
        For(j,0,n-1) ans+=(1/double(vis[j]));
        cout<<sp(20)<<ans;
    }
}