#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <vector>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>

using namespace std;

int main(){
    vector<long>viOrd(10,0);
    for(int i = 1; i < 10; i++){
        viOrd[i] = viOrd[i-1] * 10 + 9;
    }
    long n,k;
    cin >> n >> k;
    long nTmp = n;
    for(int i = 0; i < k; i++){
        vector<long> viTmp;
        long nThis = nTmp;
        while(nThis > 0){
            viTmp.push_back(nThis%10);
            nThis /= 10;
        }
        sort(viTmp.begin(), viTmp.end());
        long iSize = long(viTmp.size());
        nTmp = 0;
        for(long i = 0; i < iSize/2; i++){
            nTmp += (viTmp[iSize-i-1]-viTmp[i]) * (viOrd[iSize-i-1]-viOrd[i]);
        }
    }
    cout << nTmp << endl;
    
    return 0;
}

#include<bits/stdc++.h>
#define debug(a) cout<<#a<<"="<<a<<endl
#define rep(i,a,b) for(ll i=a,i##end=b;i<=i##end;++i)
#define drep(i,a,b) for(ll i=a,i##end=b;i>=i##end;--i)
#define erep(i,a) for(ll i=hd[a],y;(y=to[i]);i=nxt[i])
typedef long long ll;
//57200710018

using namespace std;
char IO;
inline ll rd() {
	ll res=0,f=1;
	while(IO=getchar(),IO<48||IO>57)if(IO=='-')f=0;
	do res=(res<<3)+(res<<1)+(IO^48);
	while(IO=getchar(),IO>=48&&IO<=57);
	if(f)return res;
	return -res;
}
inline void Max(ll &a,ll b) {
	((a<b)&&(a=b));
}
inline void Min(ll &a,ll b) {
	((a>b)&&(a=b));
}
bool let;
const ll M=2005,P=1e9+7;
ll mp[M][M],s1[M][M],s2[M][M];
char s[M];
bool vis[M][M];
bool vio;
ll Pow(ll a,ll b) {
	ll res=1;
	for(; b; b>>=1,a=a*a%P)
		if(b&1)res=res*a%P;
	return res;
}
int main() {
//	printf("%.3f",(&vio-&let)/1024.0/1024);
	ll n=rd(),m=rd(),tot=0,ans=0;
	rep(i,1,n) {
		scanf("%s",s+1);
		rep(j,1,m)if(s[j]=='.')mp[i][j]=1,tot++;
	}
//	rep(i,1,n){rep(j,1,m)printf("%d",mp[i][j]);puts("");}
	rep(i,1,n) {
		rep(j,1,m) {
			if(!vis[i][j]&&mp[i][j]) {
				ll t=j;
				while(mp[i][t])t++;
				rep(k,j,t-1) {
					s1[i][k]=t-j;
					vis[i][k]=1;
				}
			}
		}
	}
	memset(vis,0,sizeof vis);
	rep(i,1,n) {
		rep(j,1,m) {
			if(!vis[i][j]&&mp[i][j]) {
				ll t=i;
				while(mp[t][j])t++;
				rep(k,i,t-1) {
					s2[k][j]=t-i;
					vis[k][j]=1;
				}
			}
		}
	}
	rep(i,1,n)rep(j,1,m)if(mp[i][j]) {
		ll t=s1[i][j]+s2[i][j]-1;
		ans=(ans+(Pow(2,t)-1)*Pow(2,tot-t)%P)%P;
	}
	printf("%lld",ans);
}