#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_ll.hpp>

#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,b,a) for(ll i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
double pi=acos(-1);
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
// #define mp make_pair
#define pq priority_queue
const ll mod=1000000007;
#define f first
#define s second
#define pii pair< ll, ll >
#define vi vector<ll>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc ll t; cin >> t; while(t--)

// using namespace boost::multiprecision;
using namespace std;
void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}


const ll N=1000005;
ll fact[N],invfact[N];
ll power(ll x,ll y){
  if(y<=0) return 1LL;
  ll z=power(x,y/2);
  if(y%2) return (((z*z)%mod)*x)%mod;
  return (z*z)%mod;
}

void pre(){
  fact[0]=invfact[0]=invfact[1]=fact[1]=1;
  rep(i,2,N) fact[i]=(i*fact[i-1])%mod;
  rep(i,2,N) invfact[i]=(invfact[i-1]*power(i,mod-2))%mod;
}
ll nCr(ll n,ll k){ if (k < 0 || k > n) return 0; return (((fact[n]*invfact[n-k])%mod)*invfact[k])%mod; }



const ll N1=1e6+1;
vector<ll> isprime(N1,1),prime;
void seive(){
  rep(i,2,sqrt(N1)+1){
      if(isprime[i]){
        for(ll j=i*i;j<N1;j+=i) isprime[j]=0;
        prime.pb(i);
      }
  }
  rep(i,sqrt(N1)+1,N1) if(isprime[i]) prime.pb(i);
}



struct dsu {
    vector<ll> par, rank;
    dsu(ll n): par(n+1), rank(n+1) {
        for (ll i = 0; i <= n; i++) {
            par[i] = i;
            rank[i]= 1;
        }
    }
    ll root(ll a) {
        if (a == par[a]) return a;
        return par[a] = root(par[a]);
    }
    void merge(ll a, ll b) {
        a = root(a);
        b = root(b);
        if (a == b) return;
        if (rank[a] > rank[b]) swap(a, b);
        par[b] = a;
    }
    set<ll> parent(ll n){
        set<ll> s;
        for(ll i=1;i<=n;i++){
            s.insert(root(i));
        }
        return s;
    }
};
void solve(){
  ll n,m;
  cin>>n>>m;
  vector<int>h(n),w(m);
  rep(i,0,n) cin>>h[i];
  rep(i,0,m) cin>>w[i];
  sort(all(h));
  vector<ll> dp(n+1,0),suf(n+1,0);
  for(ll i=0;i+1<n;i+=2){
    dp[i]=(i==0?0:dp[i-1])+abs(h[i+1]-h[i]);
    dp[i+1]=dp[i];
  }
  for(ll i=n-1;i-1>=0;i-=2){
    suf[i]=(i==n-1?0:suf[i+1])+abs(h[i]-h[i-1]);
    suf[i-1]=suf[i];
  }
  ll ans=LLONG_MAX;
  rep(i,0,m){
    auto id=lower_bound(all(h),w[i]);
    if(id==h.end()) ans=min(ans,dp[n-2]+abs(w[i]-h[n-1]));
    else if(id==h.begin()) ans=min(ans,suf[1]+abs(w[i]-h[0]));
    else{
      ll idx=id-h.begin();
      if(idx%2==0) ans=min(ans,dp[idx-1]+abs(w[i]-h[idx])+suf[idx+1]);
      else ans=min(ans,(idx-2>=0?dp[idx-2]:0)+abs(w[i]-h[idx-1])+suf[idx]);
    }
  }
  cout<<ans<<endl;
}
int32_t main(){
    optimizeIO();
    {solve();}
}

#pragma GCC diagnostic warning "-Wextra"
#pragma GCC diagnostic warning "-Wshadow"
#include <bits/stdc++.h>
using namespace std;

template <class A, class B> bool cmin(A& a, B b) { return a > b && (a = b, true); }
template <class A, class B> bool cmax(A& a, B b) { return a < b && (a = b, true); }

signed main() {
  cin.tie(nullptr)->sync_with_stdio(false);

  long N, M;
  cin >> N >> M;
  vector<long> H(N);
  for (long i = 0; i < N; i++) cin >> H.at(i);
  vector<long> W(M);
  for (long i = 0; i < M; i++) cin >> W.at(i);

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

  vector<long> L, R;
  for (long i = 0; i + 1 < N; i += 2) {
    L.push_back(H.at(i + 1) - H.at(i));
  }
  for (long i = 1; i + 1 < N; i += 2) {
    R.push_back(H.at(i + 1) - H.at(i));
  }

  auto cs = [](auto vec) {
    vector<long> ret((long)vec.size() + 1);
    partial_sum(vec.begin(), vec.end(), ret.begin() + 1);
    return ret;
  };

  L = cs(L);
  R = cs(R);

  long mi = LONG_MAX;
  for (const auto& a : W) {
    // long opp = lower_bound(H.begin(), H.end(), a) - H.begin();
    // if (opp & 1) opp--;
    // cmin(mi, L.at(opp / 2) + abs(H.at(opp) - a) + (R.back() - R.at(opp / 2)));
    long opp = upper_bound(H.begin(), H.end(), a) - H.begin();
    if (opp & 1) opp--;
    cmin(mi, L.at(opp / 2) + abs(H.at(opp) - a) + (R.back() - R.at(opp / 2)));
  }
  cout << mi << '\n';
}