#include <bits/stdc++.h>
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<x<<endl
using namespace std;
using ll = long long;
const ll MOD = 1e9+7; // 998244353
const ll LINF = LLONG_MAX; // ~ 10^18 ~ 1<<60
const int INF = INT_MAX;
const double PI = acos(-1);



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

	vector<ll> h(n);
	vector<ll> w(m);

	rep(i,0,n){
		cin >> h[i];
	}

	rep(i,0,m){
		cin >> w[i];
	}

	sort(all(h));

	vector<ll> L(n, 0);
	vector<ll> R(n, 0);

	for(int i = 0; i <= n - 3; i += 2){
		ll x = abs(h[i] - h[i + 1]);
		L[i] = x;
		L[i + 1] = x;
		if(i != 0){
			L[i] += L[i - 1];
			L[i + 1] += L[i - 1];
		}
	}

	for(int i = n - 1; i >= 1; i -= 2){
		ll x = abs(h[i] - h[i - 1]);
		R[i] = x;
		R[i - 1] = x;
		if(i != n - 1){
			R[i] += R[i + 1];
			R[i - 1] += R[i + 1];
		}
	}

	ll ans = LINF;

	for(int i = 0; i < m; i++){
		ll it = lower_bound(all(h), w[i]) - h.begin();
		ll temp = 0;
		if(it % 2 == 1){
			temp = abs(w[i] - h[it - 1]);
			if(it - 2 >= 0) temp += L[it - 2];
			if(it + 1 < n) temp += R[it + 1];
		}else{
			temp = abs(w[i] - h[it]);
			if(it - 1 >= 0) temp += L[it - 1];
			if(it + 1 < n) temp += R[it + 1];
		}
		ans = min(ans, temp);
	}

	cout << ans << endl;

}
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define lowbit(x) (x & (-x))

const ll inf  = 1e17+9;
const ll mod  = 1e9+7;
const ll maxn = 2e5+8;

int n,m;
int h[maxn],w[maxn];
ll L[maxn],R[maxn];
ll ans=1e18;

int main() {
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin>>n>>m;
    for(int i=1;i<=n;++i) cin>>h[i];
    for(int i=1;i<=m;++i) cin>>w[i];

    sort(h+1,h+1+n);

    for(int i=2;i<=n;i+=2) L[i]=L[i-2]+abs(h[i]-h[i-1]);
    for(int i=n-1;i>=1;i-=2) R[i]=R[i+2]+abs(h[i]-h[i+1]);

    for(int i=1;i<=m;++i){
        int pos=lower_bound(h+1,h+1+n,w[i])-h;
        if(pos%2==0) pos--;
        ans=min(ans,L[pos-1]+R[pos+1]+abs(h[pos]-w[i]));
    }

    cout<<ans<<endl;

    return 0;
}

