#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define INF 0x3f3f3f3f
#define pi M_PI
typedef pair<ll, ll> llPair;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<bool> vb;
typedef priority_queue<ll> pqll;
ll MOD = 1000000007;
/*
So much for summer love and saying "us"
'Cause you weren't mine to lose
You weren't mine to lose, no
*/
int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll t;
    t = 1;
    for (ll z = 0; z < t; ++z)
    {
        ll n, m;
        cin >> n >> m;
        vll v(n);
        for (ll i = 0; i < n; ++i)
        {
            cin >> v[i];
        }
        sort(v.begin(), v.end());
        vll forw(n / 2);
        for (ll i = 0; i < n / 2; ++i)
        {
            forw[i] = abs(v[2 * i] - v[2 * i + 1]);
        }
        vll back(n / 2);
        for (ll i = 0; i < n / 2; ++i)
        {
            back[i] = abs(v[(n - 1) - 2 * i] - v[(n - 1) - 2 * i - 1]);
        }
        vll preff(n / 2 + 1, 0);
        vll prefb(n / 2 + 1, 0);
        for (ll i = 0; i < n / 2; ++i)
        {
            preff[i + 1] = preff[i] + forw[i];
            prefb[i + 1] = prefb[i] + back[i];
        }
        ll res = 1000000000000000000;
        for (ll i = 0; i < m; ++i)
        {
            ll h;
            cin >> h;
            ll ans = -1;
            if (h <= v[0])
            {
                ans = 0;

            }
            else if (h >= v[n - 1])
            {
                ans = n;
            }
            else
            {
                ll l = 0;
                ll r = n - 1;
                while (l <= r)
                {
                    ll m = l + (r - l) / 2;
                    if (v[m] >= h)
                    {
                        ans = m;
                        r = m - 1;
                    }
                    else l = m + 1;
                }
            }
            if (ans % 2 == 0)
            {
                ll temp = 0;
                temp += preff[ans / 2];
                temp += prefb[(n + 1) / 2 - (ans / 2) - 1];
                temp += abs(h - v[ans]);
                res = min(res, temp);
            }
            else
            {
                ll temp = 0;
                temp += preff[ans / 2];
                temp += prefb[(n + 1) / 2 - (ans / 2) - 1];
                temp += abs(h - v[ans - 1]);
                res = min(res, temp);
            }
        }
        cout << res << '\n';
    }


    return 0;
}

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
    ll n,m;
    cin >> n >> m;
    vector<ll> h(n);
    vector<ll> w(m);
    for(int i = 0;i < n;i++)cin >> h[i];
    for(int i = 0;i < m;i++)cin >> w[i];
    sort(h.begin(),h.end());
    sort(w.begin(),w.end());

    vector<ll> cost(n + 1);//i番目の隙間に先生を入れた時 先生はi/2組目
    vector<ll> part(n + 1);//,,　先生と組む人
    ll back = 0;
    for(int i = n - 1;i >= 1;i--){
        if(i % 2 == 0)back += h[i] - h[i - 1];
    }
    ll nowpart = -2;
    ll front = 0;
    for(int i = 0;i < n + 1;i++){
        if(i % 2 == 0){
            nowpart += 2;
            if(i != 0){
                front += h[i - 1] - h[i - 2];
                back -= h[i] - h[i - 1];
            }
        }
        part[i] = nowpart;
        cost[i] = front + back;
      //cout << i << " " << front << " " << back << " " << cost[i] << endl;
    }
  
  //cout << part[0] << part[1] << part[2] << part[3] << part[4] << part[5] << endl;
  //cout << cost[0] << cost[1] << cost[2] << cost[3] << endl;

    ll res = pow(10,18);
    ll it = 0;
    for(int i = 0;i < m;i++){
        while(1){
            if(w[i] > h[it] && it < n)it++;
            else break;
        }
      //cout << i << " " << h[part[it]] << w[i] << endl;
        res = min(res,cost[it] + abs(h[part[it]] - w[i]));
    }
    cout << res << endl;
}