#include<iostream>
#include<vector>
#include<string>
#include<stack>
using namespace std;
#define ll long long 
#define f(i,a,b) for(register ll i=a;i<=b;++i)

#define pb push_back
#define mp make_pair
#define N 2005
#define Mod 1000000007
inline ll read()
{
	ll s=0,w=1;
	register char ch=getchar();
	while(ch<'0'||ch>'9') { if(ch=='-') w=-1;ch=getchar();}
	while(ch>='0'&&ch<='9') { s=(s<<1)+(s<<3)+(ch^48);ch=getchar();}
	return s*w;
}
char Mat[N][N];
ll X[N][N],Y[N][N],sqr[N*N]={1ll};
stack<ll>st;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	ll n=read(),m=read(),sum=0,ans=0;
	
	f(i,1,n*m+2) sqr[i]=(sqr[i-1]*2)%Mod;
	f(i,1,n) scanf("%s",Mat[i]+1);
	
	f(i,1,n) f(j,1,m) if(Mat[i][j]=='.') ++sum;
	
	f(i,1,n)
	{
		while(st.size()) st.pop();
		for(ll j=1;j<=m+1;++j)
		{
			if(j==m+1||Mat[i][j]=='#')
			{
				ll siz=st.size();
				while(st.size())
					X[i][st.top()]=siz,st.pop();
			}
			else st.push(j);
		}
	}
	f(j,1,m)
	{
		while(st.size()) st.pop();
		for(ll i=1;i<=n+1;++i)
		{
			if(i==n+1||Mat[i][j]=='#')
			{
				ll siz=st.size();
				while(st.size())
					Y[st.top()][j]=siz,st.pop();
			}
			else st.push(i);
		}
	}
	/*cout<<"Test X:"<<endl;
	f(i,1,n){
		f(j,1,m) cout<<X[i][j]<<" ";cout<<endl;
	}
	cout<<"Test Y:"<<endl;
	f(i,1,n){
		f(j,1,m) cout<<Y[i][j]<<" ";cout<<endl;
	}*/
	f(i,1,n) f(j,1,m)
	{
		if(Mat[i][j]!='.') continue;
		ll x=sqr[sum-X[i][j]-Y[i][j]+1];
		ans=(ans+((sqr[sum]-x)%Mod+Mod)%Mod)%Mod;
	}
	cout<<ans;
	return 0;
}
#include <bits/stdc++.h>
 
using namespace std;
using i128 = __int128_t;
using u128 = __uint128_t;
using u64 = uint64_t;

//define
#define int long long
#define ll int
#define trav(i,v)   for(auto i: v)
#define rep(i,n)    for(int i=0;i<n;i++)
#define repu(i,k,n) for(int i=k;i<=n;i++)
#define repd(i,k,n) for(int i=k;i>=n;i--)
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define all(v)  v.begin(), v.end()
#define itn int 
#define sz(x) (int)x.size()
    
//typedef
typedef unsigned long long ull;
typedef long double ld;
typedef std::pair<int, int> pii;
typedef std::vector<int> vi;
typedef std::vector< pii > vii;
typedef std::vector< std::vector<int> > vvi;
typedef std::vector< std::pair < pii, int > > vpp;
 
const long long MOD = 1000000007;
// const long long MOD = 998244353;
const long double PI = 3.141592653589793238;
const long long pi = 31415926;
const long long inf = 1000000000000000000;
const long long small_inf = INT_MAX;

int modpow(int x, int n, int mod = MOD){ int res=1; while(n>0){ if(n&1) res=res*x%mod; x=x*x%MOD; n>>=1;} return res;}
int power(int x, int n){ int res=1; while(n>0){ if(n&1) res=res*x; x=x*x; n>>=1; } return res;}

void init(){

}

int ncr(int n, int r){
    if(r<0 || r>n){
        return 0;
    }
    if(n<0)
        return 0;
    ll x = n*(n-1);
    x/=2;
    return x;
}

void solve()
{
/*Don't hurry, nothing good comes if you rush*/
    int n, k;
    cin>>n>>k;
    repu(x1,3,3*n){
        int x = x1-3;
        int tot = 0;
        tot+=1ll*ncr(2+(x), 2);
        tot-=3ll*ncr(2+(x-n), 2);
        tot+=3ll*ncr(2+(x-2*n), 2);
        tot-=1ll*ncr(2+(x-3*n), 2);
        if(tot<k){
            k-=tot;
            continue;
        }
        x = x1;
        // cout<<k<<endl<<endl;
        repu(i,1,n){
            int left = x-i;
            if(left<=1 || left>2*n)
                continue;
            int mx = min(n,left-1ll);
            int mn = max(1ll,left-mx);
            // cout<<mx<<" "<<mn<<" "<<mx-mn+1<<endl;
            if(k>mx-mn+1){
                k-=mx-mn+1;
                continue;
            }
            // cout<<i<<endl;
            repu(j,1,n){
                if(x-i-j<=0 || x-i-j>n)
                    continue;
                k--;
                if(k==0){
                    cout<<i<<" "<<j<<" "<<x-i-j<<endl;
                    return;
                }
            }
            return;
            // break;
        }
    }
    // cout<<k<<endl;
}

signed main(){
    // #ifndef ONLINE_JUDGE
    //    freopen("./input.txt", "r", stdin);
    //    freopen("./output.txt", "w", stdout);
    // #endif
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int t23 = 1, tt23 = 1; 
    // cin>>t23;
    init();
    while(tt23<=t23)
    {
        // cout<<"Case #"<<tt23<<": ";
        solve();
        tt23++;
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}   