#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using P = pair<int,int>;
#define rep(i,n) for (int i = 0; i < (int)(n) ; i++)
#define rep2(i,a,b) for (int i = (a); i < (int)(b); i++)
#define repR(i,n) for (int i = (int)(n)-1; i >= 0; i--)
#define repR2(i,a,b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define ENDL '\n'
#define pb push_back
#define SIZE(a) (int)(a.size())
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define UNIQUE(a) a.erase(unique(all(a)),a.end());
#define debug(x) cout<<(#x)<<" is : "<<x<<endl;
#define debugc(vec) {cout<<(#vec)<<" is below; ---"<<endl;for(auto elements:vec)cout<<elements<<" ";cout<<endl<<"----------------"<<endl;}
inline string rev(string s) {string t(s.rbegin(), s.rend()); return t;}
template<class T> inline bool chmin(T &a, T b) { if(a>b) {a=b; return 1;} return 0;}
template<class T> inline bool chmax(T &a, T b) { if(a<b) {a=b; return 1;} return 0;}
constexpr ll INF = (1LL<<30)-1;
constexpr ll INFLL = (1LL<<62)-1;
constexpr ld PI = 3.14159265358979323846L;

int main() {
    cout << fixed << setprecision(15);
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    int n,m; cin>>n>>m;
    ll ans=INFLL;
    vll a(n), w(m), lsum(n), rsum(n);
    rep(i, n) cin>>a[i];
    rep(i, m) cin>>w[i];
    sort(ALL(a));
    sort(ALL(w));
    for(int i=1; i<=n-2; i+=2) {
        if(i==1) lsum[i]=a[i]-a[i-1];
        else lsum[i]=lsum[i-2] + a[i]-a[i-1];
    }
    for(int i=n-2; i>=1; i-=2) {
        if(i==n-2) rsum[i]=a[i+1]-a[i];
        else rsum[i]=rsum[i+2] + a[i+1]-a[i];
    }

    auto floorodd =  [](int x) -> int {
        if(x<=0) return 0;
        if(x%2==0) return x-1;
        return x;
    };
    auto ceilodd = [&](int x) -> int {
        if(x>=n-1) return n-1;
        if(x%2==0) return x+1;
        return x;
    };

    int left=0, right=1;
    ll sum=0;
    if(w[0]<a[0]) {left=-1; right=0;}
    else {
        while(left<n-1 && a[left+1]<w[0]) {
            left++;
            right++;
        }
    }
    sum += lsum[floorodd(left)] + rsum[ceilodd(right)];
    if(left%2==0) sum+=w[0]-a[left];
    else sum+=a[right]-w[0];
    chmin(ans, sum);

    for(int i=1; i<m; i++) {
        sum=0;
        while(left<n-1 && a[left+1]<w[i]) {
            left++;
            right++;
        }
        sum += lsum[floorodd(left)] + rsum[ceilodd(right)];
        if(left%2==0) sum+=w[i]-a[left];
        else sum+=a[right]-w[i];

        chmin(ans, sum);
    }
    cout << ans << endl;
}
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

constexpr ll mod=1e9+7;

char c[2010][2010];
int yoko[2010][2010];
int tate[2010][2010];

ll mod_pow(ll a,ll b){
	a%=mod;
	if(b==0)return 1;
	if(b==1)return a;
	ll res=mod_pow(a,b/2)%mod;
	res*=res; res%=mod;
	if(b%2)res*=a;
	return res%mod;
}

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int h,w; cin >> h >> w;
	int al=0;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cin >> c[i][j];
			if(c[i][j]=='.')al++;
		}
	}
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(c[i][j]=='.'){
				int cnt=0;
				int jj=j;
				while(jj<w and c[i][jj]=='.'){
					cnt++; jj++;
				}
				while(j<jj){
					yoko[i][j]=cnt;
					j++;
				}
			}
		}
	}
	for(int i=0;i<w;i++){
		for(int j=0;j<h;j++){
			if(c[j][i]=='.'){
				int cnt=0;
				int jj=j;
				while(jj<h and c[jj][i]=='.'){
					cnt++; jj++;
				}
				while(j<jj){
					tate[j][i]=cnt;
					j++;
				}
			}
		}
	}
	ll res=0;
	ll aaa=mod_pow(2,al);
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(c[i][j]=='.'){
				res+=aaa;
				res-=mod_pow(2,al-tate[i][j]-yoko[i][j]+1);
				if(res>mod)res-=mod;
				if(res<0)res+=mod;
			}
		}
	}
	if(res<0)res+=mod;
	cout << res << endl;
}
