/*
{
######################
#       Author       #
#        Gary        #
#        2020        #
######################
*/
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define POB pop_back
#define ff fflush(stdout)
#define fastio ios::sync_with_stdio(false)
#define check_min(a,b) a=min(a,b)
#define check_max(a,b) a=max(a,b)
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
/*}
*/
priority_queue<int,vector<int>,greater<int> > heap;
int h[200000+20],w[200000+20];
int dp1[200000+20],dp2[200000+20];
int main(){
	fastio;
	int n,m;
	cin>>n>>m;
	rb(i,1,n) cin>>h[i];
	rb(i,1,m) cin>>w[i],heap.push(w[i]);
	sort(h+1,h+1+n);
	rb(i,2,n){
		dp1[i]=dp1[i-2]+h[i]-h[i-1];
	}
	rl(i,n-1,1){
		dp2[i]=dp2[i+2]+h[i+1]-h[i];
	}
	LL best=1e18;
	rb(i,0,n){
		while(!heap.empty()&&(i==n||heap.top()<=h[i+1])){
			LL rest=0;
			if(i&1){
				rest+=dp1[i-1];
				rest+=heap.top()-h[i];
				rest+=dp2[i+1];
			}
			else{
				rest+=dp1[i];
				rest+=h[i+1]-heap.top();
				rest+=dp2[i+2];
			}
			check_min(best,rest);
			heap.pop();
		}
	}
	cout<<best<<endl;
	return 0;
}
/** 程序框架：
  *
  *
  *
  *
  **/

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define INF 100000000000000 //10^14
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
  if ((x += a.x) >= mod) x -= mod;
  return *this;
  }
  mint& operator-=(const mint a) {
  if ((x += mod-a.x) >= mod) x -= mod;
  return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
  if (!t) return 1;
  mint a = pow(t>>1);
  a *= a;
  if (t&1) a *= *this;
  return a;
  }
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

mint mpow(mint x, ll y){
  if(y == 0){
    return 1;
  }
  if(y % 2 == 0){
    mint a = mpow(x, y / 2);
    return a * a;
  }
  else{
    mint a = mpow(x, y / 2);
    return a * a * x;
  }
}

int main()
{
    ll H, W;
    cin >> H >> W;
    vector<string> S(H);
    rep(i, H){
      cin >> S.at(i);
    }
    mint ans = 0;
    vector<vector<ll>> clut_r(H, vector<ll>(1, -1));
    rep(i, H){
      rep(j, W){
        if(S.at(i).at(j) == '#'){
          clut_r.at(i).push_back(j);
        }
      }
      clut_r.at(i).push_back(W);
    }
    vector<vector<ll>> clut_c(W, vector<ll>(1, -1));
    rep(i, W){
      rep(j, H){
        if(S.at(j).at(i) == '#'){
          clut_c.at(i).push_back(j);
        }
      }
      clut_c.at(i).push_back(H);
    }
    vector<vector<ll>> space(H, vector<ll>(W, 0)); //各マスを照らす照明を置けるマスの数
    rep(i, H){
      ll p = 0;
      rep(j, W){
        ll left = clut_r.at(i).at(p);
        ll right = clut_r.at(i).at(p+1);
        if(S.at(i).at(j) == '#'){
          p++;
          continue;
        }
        space.at(i).at(j) += right-left-1;
      }
    }
    rep(i, W){
      ll p = 0;
      rep(j, H){
        ll left = clut_c.at(i).at(p);
        ll right = clut_c.at(i).at(p+1);
        if(S.at(j).at(i) == '#'){
          p++;
          continue;
        }
        space.at(j).at(i) += right-left-2;
      }
    }
    ll K = 0;
    rep(i, H){
      rep(j, W){
        if(S.at(i).at(j) == '.'){
          K++;
        }
      }
    }
    rep(i, H){
      rep(j, W){
        if(S.at(i).at(j) == '.'){
          ans += mpow(2, K) - mpow(2, K-space.at(i).at(j)); //全体 - (i,j)を照らさない置き方
        }
      }
    }
    cout << ans << endl;
}