#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#pragma region Macros
#define FOR(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define rep(i, n) FOR(i, 0, n)

template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

template <class T> string join(const T &v, const string delim = ",")
{
    if (v.empty())
        return "";

    ostringstream res;
    res << v[0];
    for (int i = 1; i < v.size(); i++)
    {
        res << delim << v[i];
    }
    return res.str();
}

#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << ":" << #x << " = " << (x) << endl;
#else
#define dbg
#endif

#pragma endregion Macros


ll g(int N, int M, vector<ll>& H, vector<ll>& W, vector<ll>& lsum, vector<ll>& rsum, ll w, int idx){
    ll res = abs(H[idx] - w);
    res += lsum[idx / 2];
    res += rsum[(idx+1)/ 2];

    /*
    dbg("--");
    dbg(w);
    dbg(idx);
    dbg(res);
    */
    return res;
}

ll f(int N, int M, vector<ll>& H, vector<ll>& W, vector<ll>& lsum, vector<ll>& rsum, ll w){
    ll res = 1LL<<60;
    int idx = lower_bound(H.begin(), H.end(),w) - H.begin();
    if(idx%2==0) {
        if (idx < N) chmin(res, g(N, M, H, W, lsum, rsum, w, idx));
    }else{
        if (idx+1 < N) chmin(res, g(N, M, H, W, lsum, rsum, w, idx+1));
        if (idx-1 >=0) chmin(res, g(N, M, H, W, lsum, rsum, w, idx-1));
    }
    return res;
}

int main()
{
    int N, M;
    cin >> N >> M;

    vector<ll> H(N);
    rep(i, N) cin >> H[i];
    vector<ll> W(M);
    rep(i, M) cin >> W[i];

    sort(H.begin(), H.end());

    vector<ll> diff1(N / 2), diff2(N/2);
    for(int i=0;i<N/2;i++){
        diff1[i] = abs(H[i*2] - H[i*2 + 1]);
        diff2[i] = abs(H[i*2+1] - H[i*2+2]);
    }

    vector<ll> lsum(N / 2 + 1), rsum(N / 2 + 1);
    for(int i=1;i<N/2+1;i++){
        lsum[i] = lsum[i - 1] + diff1[i-1];
    }
    for(int i=N/2-1;i>=0;i--){
        rsum[i] = rsum[i + 1] + diff2[i];
    }

    ll ans = 1LL<<60;
    for(auto w: W){
        ll res  = f(N,M,H,W,lsum,rsum,w);
        chmin(ans, res);
    }

    cout << ans << endl;
}

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

const int MAX = 2e5 + 10;
ll qian[MAX] , hou[MAX] , w[MAX] , h[MAX];
int N , M;
int main() {
	cin >> N >> M;
	register int i;
	for(i = 1;i <= N; ++i)
		cin >> h[i];
	for(i = 1;i <= M; ++i)
		cin >> w[i];
	sort(h + 1 , h + N + 1);
	for(i = 2; i <= N; i += 2)
		qian[i] = qian[i - 2] + abs(h[i] - h[i - 1]);
	for(i = N - 1; i >= 1; i -= 2)
		hou[i] = hou[i + 2] + abs(h[i + 1] - h[i]);
	ll ans = 1e18;
	for(i = 1; i <= M; ++i) {
		int pos = lower_bound(h + 1 , h + N + 1 , w[i]) - h;
		if(pos % 2 == 0) --pos;
		ans = min(ans , qian[pos - 1] + hou[pos + 1] + abs(h[pos] - w[i]));
	}
	printf("%lld\n" , ans);
	return 0;
}