
#include <bits/stdc++.h>
#define fastio()                  \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)
#define pb push_back
#define show(x) cout << (#x) << " : " << x << endl;
#define ll long long
#define ull unsigned long long
#define ld long double
#define pow power
#define mp make_pair
#define ff first
#define ss second
#define pii pair<ll, ll>
#define sq(x) ((x) * (x))
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define siz(a) int((a).size())
#define For(i,a,b) for(int (i)=(a);(i) < (b); ++(i))
#define endl "\n"
#define pi 3.14159265
const ll mod = 1000 * 1000 * 1000 + 7;
const ll mod1 = 998244353;
const ll INF     = 1ll*1000*1000*1000*1000*1000*1000 + 7; 
using namespace std;

ll power(ll x, ll y) 
{ 
   ll res = 1;      
  
   
    while (y > 0) 
    { 
       
        if (y & 1) 
            res = (long long)(res*x); 
  

        y = y>>1; 

        x = (long long)(x*x);

        //cout<<x<<'\n'; 
    } 
    return res; 
} 



ll pre[200005];
ll suf[200005];


int main()
{

#ifndef ONLINE_JUDGE    
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif

fastio();

    ll n,m;
    cin>>n>>m;

    vector <ll> a(n); vector <ll> b(m);
    For(i,0,n)
    cin>>a[i];

    For(i,0,m)
    cin>>b[i];

    sort(all(a));
    sort(all(b));

   

    for(int i=0;i<n;i+=2) {
        if (i>0) 
            pre[i]=a[i+1]-a[i]+pre[i-2];
        else 
            pre[i]=a[i+1]-a[i];
    }


    for(int i=n-1;i>=1;i-=2) {
        if (i<n-1) 
            suf[i]=a[i]-a[i-1]+suf[i+2];
        else 
            suf[i]=a[i]-a[i-1];  
    }

    //cout<<pre[2]<<endl;

    ll ans=INF;
    for(int i=0;i<m;i++) {
        ll pos=lower_bound(all(a),b[i])-a.begin();

            if (pos&1) {
                ans=min(ans,suf[pos+1]+(pos-3>=0?pre[pos-3]:0LL)+abs(b[i]-a[pos-1]));
            } else {
                ans=min(ans,suf[pos+2]+(pos-2>=0?pre[pos-2]:0LL)+abs(b[i]-a[pos]));
            }
    }
    cout<<ans;

return 0;
}

// check all product based operations for integer overflow



#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<climits>
using namespace std;
int main(){
  int n,m;
  long long children[200005];
  long long teacher[200005];

  cin>>n>>m;
  for(int i=1;i<=n;i++){
    cin>>children[i];
  }
  for(int i=1;i<=m;i++){
    cin>>teacher[i];
  }

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

  long long left_sum[100005]={0};
  long long right_sum[100005]={0};
  for(int i=1;i<n;i+=2){
    left_sum[(i+1)/2]=llabs(children[i]-children[i+1])+left_sum[(i+1)/2-1];
    right_sum[(i+1)/2]=llabs(children[i+1]-children[i+2])+right_sum[(i+1)/2-1];
  }

  /*
  cout<<endl<<"left"<<endl;
  for(int i=0;i<=n/2;i++){
    cout<<left_sum[i]<<endl;
  }
  cout<<endl<<"right"<<endl;
  for(int i=0;i<=n/2;i++){
    cout<<right_sum[i]<<endl;
  }
  */

  long long minimum=LLONG_MAX;
  for(int i=1;i<=m;i++){
    long long sum=0;
    int index=upper_bound(children+1,children+n+1,teacher[i])-1-children;
    if(index%2==0){
      sum+=llabs(teacher[i]-children[index+1])+right_sum[n/2]-right_sum[index/2]
	+left_sum[index/2];
    }else{
      sum+=llabs(teacher[i]-children[index])+right_sum[n/2]-right_sum[index/2]
	+left_sum[index/2];
    }
    /*
    cout<<"target="<<teacher[i]<<endl;
    cout<<"sum="<<sum<<endl<<endl;
    */
    minimum=min(minimum,sum);
  }
  cout<<minimum<<endl;
  return(0);
}