#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define pii pair<int,int>
#define vi vector<int>



int main() {
    int h,w;
    cin>>h>>w;
    vector<string> grid(h);
    for(int i = 0 ; i  < h ; i++)
        cin>>grid[i];

    int ans = 0;
    for(int i = 0 ; i < h ; i++) {
        int count = 0;
        for(int j = 0 ; j < w ; j++) {
            while(j < w && grid[i][j] == '.') {
                count++;
                j++;
            }
            ans += (count >= 2 ? count-1 : 0);
            count = 0;
        }
    }
    for(int i = 0 ; i < w ; i++) {
        int count = 0;
        for(int j = 0 ; j < h ; j++) {
            while(j < h && grid[j][i] == '.') {
                count++;
                j++;
            }
            ans += (count >= 2 ? count-1 : 0);
            count = 0;
        }
    }

    cout<<ans;
    return 0;
}
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, k, n) for (int i = k; i < (int)(n); i++)
#define repd(i, n) for (int i = n-1; i >= 0; i--)
#define rrepd(i, k, n) for (int i = n-1; i >= (int)(k); i--)
#define all(x) (x).begin(),(x).end()
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
//V,Pは大文字i,l,bは小文字
using ll = long long;
using Vi = vector<int>;
using VVi = vector<Vi>;
using Vl = vector<ll>;
using VVl = vector<Vl>;
using Vb = vector<bool>;
using VVb = vector<Vb>;
using P = pair<int,int>;
using Pl = pair<ll, ll>;
using Vs = vector<string>;
const ll mod = 1000000007;
const ll inf = 1000000000000000000;//10の18乗

int main() {
    ll n,m;
    cin >> n >> m;
    Vl v(n),v2(m);
    rep(i,n) cin >> v[i];
    rep(i,m) cin >> v2[i];
    sort(all(v));
    sort(all(v2));
    ll fans=inf;
    ll now=0;
    for(int i=0;i<n-1;i+=2){
        now+=v[i+1]-v[i];
    }
    int whe=m-1;
    for(int i=n-1;i>=0;i-=2){
        while(v2[whe]>=v[i]&&whe>=0) whe--;
        ll x=inf,y=inf;
        if(whe!=-1) x=abs(v2[whe]-v[i]);
        y=abs(v2[whe+1]-v[i]);
        chmin(fans,now+min(x,y));
        if(i>0){
            now-=abs(v[i-2]-v[i-1]);
            now+=abs(v[i]-v[i-1]);
        }
        //cout << fans << endl;
    }
    cout << fans << endl;


}