/**
*    author:  Dooloper
*    created: 26.10.2020 13:52:11
**/
#include <iostream>
#include <string>

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i<n;i++)
typedef pair<int,int> P;

int main() {
    ll n,k;
    cin >> n >> k;

    rep(i,k){
      int small,b;
        vector<int> tmp;
        string s=to_string(n);
        rep(j,(ll)s.size()){
            //if(s.at(j)-'0'!=0){
                tmp.push_back(s.at(j)-'0');
           // }
        }
        s="";
        sort(tmp.begin(),tmp.end());
        reverse(tmp.begin(),tmp.end());
        rep(j,(ll)tmp.size()){
          //cout << tmp.at(j) << endl;
            s.push_back(tmp.at(j)+'0');
        }
      //cout << s << endl;
      if(s=="")
        b=0;
      else
        b=stoi(s);
        s="";
        reverse(tmp.begin(),tmp.end());
        rep(j,(ll)tmp.size()){
          if(tmp.at(j)!=0)
            s.push_back(tmp.at(j)+'0');
        }
      if(s=="")
        small=0;
      else
        small=stoi(s);
    n=b-small;
//cout << b << small << endl;
    }

    cout << n << endl;

    }
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i,n) for(ll i=1;i<=(ll)(n);i++)

const int mod = 1e9+7;

template< int mod >
struct ModInt {
  int x;

  ModInt() : x(0) {}

  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

  ModInt &operator+=(const ModInt &p) {
    if((x += p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator-=(const ModInt &p) {
    if((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator*=(const ModInt &p) {
    x = (int) (1LL * x * p.x % mod);
    return *this;
  }

  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }

  ModInt operator-() const { return ModInt(-x); }

  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }

  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }

  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }

  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }

  bool operator==(const ModInt &p) const { return x == p.x; }

  bool operator!=(const ModInt &p) const { return x != p.x; }

  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }

  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while(n > 0) {
      if(n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }

  friend ostream &operator<<(ostream &os, const ModInt &p) {
    return os << p.x;
  }

  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt< mod >(t);
    return (is);
  }

  static int get_mod() { return mod; }
};

using modint = ModInt< mod >;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);

  int h,w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i,h) cin >> s[i];
  vector<vector<int>> lit(h,vector<int>(w,0));
  rep(i,h){
    int cnt = 0;
    rep(j,w){
      if(s[i][j]=='#'){
        cnt = 0;
      }
      else{
        lit[i][j] += cnt;
        cnt++;
      }
    }
    cnt = 0;
    for(int j = w-1;j>=0;j--){
      if(s[i][j]=='#'){
        cnt = 0;
      }
      else{
        lit[i][j] += cnt;
        cnt++;
      }
    }
  }

  rep(j,w){
    int cnt = 0;
    rep(i,h){
      if(s[i][j]=='#'){
        cnt = 0;
      }
      else{
        lit[i][j] += cnt;
        cnt++;
      }
    }
    cnt = 0;
    for(int i = h-1;i>=0;i--){
      if(s[i][j]=='#'){
        cnt = 0;
      }
      else{
        lit[i][j] += cnt;
        cnt++;
      }
    }
  }
  // rep(i,h)rep(j,w){
  //   cout << lit[i][j] << " \n"[j==w-1];
  // }
  modint ans = 0;
  int tot_cnt = 0;
  rep(i,h)rep(j,w) if(s[i][j]=='.') {tot_cnt++;lit[i][j]++;}
  rep(i,h)rep(j,w){
    ans += ((modint) 2).pow(tot_cnt-lit[i][j]) * (((modint) 2).pow(lit[i][j]) - 1);
  }
  cout << ans << endl;

  return 0;
    

}
