#include <bits/stdc++.h>

using namespace std;
 
typedef long long ll;
const int N=2e6+5,M=1e9+7,OO=0x3f3f3f3f;
 
 
int main(){
 
    //freopen("myfile.txt","w",stdout);
 
    int n,m;
    scanf("%d%d",&n,&m);
    vector<int> arr(n);
    for(int i=0;i<n;++i)
        scanf("%d",&arr[i]);
    sort(arr.begin(),arr.end());
    vector<ll> pre(n+1,0);
    vector<ll> suf(n+2,0);
    pre[1]=abs(arr[1]-arr[0]);
    for(int i=3;i<n;i+=2)
        pre[i]+=pre[i-2]+abs(arr[i]-arr[i-1]);
    for(int i=n-2;i>0;i-=2)
        suf[i]+=suf[i+2]+abs(arr[i]-arr[i+1]);
    ll ans=LONG_LONG_MAX;
    arr[n]=OO;
    while(m--){
        int x;
        scanf("%d",&x);
        int lo=0,hi=n,md;
        while(lo<hi){
            md=lo+(hi-lo)/2;
            if(arr[md]<=x) lo=md+1;
            else hi=md;
        }
        if(lo&1){
            ll cur=suf[lo]+abs(arr[lo-1]-x);
            if(lo-2>=0) cur+=pre[lo-2];
            ans=min(ans,cur);
        }
        else{
            ll cur=abs(arr[lo]-x);
            if(lo-1>=0) cur+=pre[lo-1];
            if(lo+1<=n) cur+=suf[lo+1];
            ans=min(ans,cur);
        }
    }
    printf("%lld\n",ans);
 
    return 0;
}
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

const int INF = INT_MAX / 2;
int dp[200005][2];

void solve() {
    int N, M;
    cin >> N >> M;
    vi H(N), W(M);
    rep(i, N)cin >> H[i];
    rep(i, M)cin >> W[i];
    sort(all(H));
    sort(all(W));
    W.erase(unique(all(W)), W.end());
    M = sz(W);
    rep(i, N + 1)rep(j, 2)dp[i][j] = INF;
    dp[0][0] = 0;

    int cur = 0;
    rep(i, N)rep(j, 2) {
        if (i < N - 1) {
            smin(dp[i + 2][j], dp[i][j] + H[i + 1] - H[i]);
        }
        while (cur != M && W[cur] < H[i])++cur;
        if (j == 0) {
            if (cur != M) {
                smin(dp[i + 1][1], dp[i][j] + W[cur] - H[i]);
            }
            if (cur > 0) {
                smin(dp[i + 1][1], dp[i][j] + H[i] - W[cur - 1]);
            }
        }
    }

    cout << dp[N][1] << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}