#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define ff first
#define ss second
int main(void){
    // Your code here!
 ios_base::sync_with_stdio(false);
 cin.tie(NULL);
 ll i,ans,m,n,s;
 ans=INT_MAX;
 cin >> n >> m;
 ll a[n],c[n];
 vector<ll> v(n),b(m);
 for(i=0;i<n;i++)
 cin >> v[i];
 for(i=0;i<m;i++)
 cin >> b[i];
 if(n==1)
 {
  for(i=0;i<m;i++)
  ans=min(ans,abs(b[i]-v[0]));
  cout << ans;
  return 0;
 }
 sort(v.begin(),v.end());
 for(i=1;i<n;i++)
 {
  a[i]=v[i]-v[i-1];
  c[i-1]=v[i]-v[i-1];
 }
 for(i=2;i<n;i++)
 {
  a[i]+=a[i-2];
  c[n-i-1]+=c[n-i+1];
 }
 for(i=0;i<m;i++)
 {
  auto it=lower_bound(v.begin(),v.end(),b[i]);
  s=0;
  if(b[i]>=v[n-1])
  s=a[n-2]+b[i]-v[n-1];
  else if(b[i]<=v[0])
  s=c[1]+v[0]-b[i];
  else if((it-v.begin())%2)
  {
   s+=c[it-v.begin()];
   s+=b[i]-v[it-v.begin()-1];
   if((it-v.begin())!=1)
   s+=a[it-v.begin()-2];
  }
  else
  {
   if(it!=v.begin())
   s+=a[it-v.begin()-1];
   s+=v[it-v.begin()]-b[i];
   if((it-v.begin())!=(n-1))
   s+=c[it-v.begin()+1];
  }
  ans=min(ans,s);
  //cout << s << " ";
 }
 cout << ans;
 return 0;
}
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

void chmin(ll& a, ll b) {
  if (a > b) a = b;
}

int main() {
  int N, M;
  cin >> N >> M;
  
  ll H[N];
  rep(i, N) {
    cin >> H[i];
  }
  sort(H, H+N);
 
  vector<ll> left(N/2), right(N/2);
  rep(i, N/2) {
    left[i] = H[2*i+1] - H[2*i];
    right[i] = H[2*(i+1)] - H[2*i+1];
    
  }
  
  vector<ll> left_sum(N/2 + 1, 0), right_sum(N/2+1, 0);
  rep(i, N/2) {
    left_sum[i+1] = left_sum[i] + left[i];
    right_sum[i+1] = right_sum[i] + right[i];
  }
  
  vector<ll> W(M);
  rep(i, M) {
    cin >> W[i];
  }
  
  ll ans = 10000000000000000;
  
  
  rep(i, M) {
    // 先生を初めて超えるindex
    int x = lower_bound(H, H +N, W[i]) - H;
    
    if (x % 2) {
      chmin(ans, left_sum[(x-1)/2] + (W[i]-H[x-1]) 
          + right_sum[(N-1)/2] - right_sum[(x-1)/2]);
    } else {
      chmin(ans, left_sum[x/2] + (H[x]-W[i])
            + right_sum[(N-1)/2] - right_sum[x/2]);
    }
  }
  
  
  cout << ans << endl;
  

}