#include <bits/stdc++.h>
// #include <atcoder/all>
// #include "icld.cpp"
using namespace std;
using ll = long long int;
using pii = pair<int,int>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using ss = string;
using db = double;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
#define V vector
#define pi 3.14159265358979
#define rep(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define ci(x) cin >> x
#define cii(x) int x;cin >> x
#define cci(x,y) int x,y;cin >> x >> y
#define co(x) cout << x << endl
void chmax(int &x,int y){x=max(x,y);}
void chmin(int &x,int y){x=min(x,y);}

int main(){
  cci(n,m);
  int n2=n/2;
  
  vi mi(n2),ma(n2),v(n);
  rep(i,0,n)ci(v[i]);

  vi tc(m);
  rep(i,0,m)ci(tc[i]);

  sort(all(v));
  sort(all(tc));
  rep(i,0,n-1)(i%2?ma:mi)[i/2]=v[i+1]-v[i];
  // rep(i,0,n2)cout<<mi[i]<<" ";

  vi smi(n2+1,0),sma(n2+1,0);
  rep(i,1,n2+1)smi[i]=smi[i-1]+mi[i-1];
  rep(i,0,n2)sma[n2-i-1]=sma[n2-i]+ma[n2-i-1];
// co("v");for(int x:v)cout<<x<<" ";co("");
// co("tc");for(int x:tc)cout<<x<<" ";co("");
// co("smi");for(int x:smi)cout<<x<<" ";co("");
// co("sma");for(int x:sma)cout<<x<<" ";co("");

  int ans=1001001001;
  rep(i,0,m){
    int nx=lower_bound(all(v),tc[i])-v.begin();
    nx/=2;
    int dis=abs(v[nx*2]-tc[i]);
    int now=smi[nx]+dis+sma[nx];
    chmin(ans,now);
  }
  co(ans);  
}
#include <bits/stdc++.h>
using namespace std;

#define dbg(v) cout << __LINE__ << ": " << #v << " = " << v << endl

const int N = 1e5 + 5;

int main() {
    int n, m;
    scanf("%d %d", &n, &m);
    vector <int> h(n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &h[i]);
    }
    sort(h.begin(), h.end());
    vector <long long> pre(n), suf(n);
    for (int i = 1; i < n; i += 2) {
        pre[i] = h[i] - h[i - 1];
        if (i > 1) {
            pre[i] += pre[i - 2];
        }
    }
    for (int i = n - 2; i >= 0; i -= 2) {
        suf[i] = h[i + 1] - h[i];
        if (i + 2 < n) {
            suf[i] += suf[i + 2];
        }
    }
    long long ans = LLONG_MAX;
    for (int it = 0; it < m; it++) {
        int w;
        scanf("%d", &w);
        int pos = lower_bound(h.begin(), h.end(), w) - h.begin();
        long long now;
        if (pos & 1) {
            now = w - h[pos - 1];
            if (pos - 2 >= 0) {
                now += pre[pos - 2];
            }
            if (pos < n) {
                now += suf[pos];
            }
        }
        else {
            now = h[pos] - w;
            if (pos - 1 >= 0) {
                now += pre[pos - 1];
            }
            if (pos + 1 < n) {
                now += suf[pos + 1];
            }
        }
        ans = min(ans, now);
    }
    printf("%lld\n", ans);
    return 0;
}
