#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repo(i, n) for(int i=1; i<=n; i++)
#define ssort(a) sort(a.begin(), a.end())
#define INF 1001001001
#define INFll 10010010010010010
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;

using namespace std;
using ull = unsigned long long;
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;

int main(){
  int n, m;
  cin >> n >> m;
  vector<int> h(n);
  vector<int> w(m);
  rep(i, n){
    cin >> h[i];
  }
  ssort(h);
  rep(i, m){
    cin >> w[i];
  }
  vector<ll> pair1((n-1)/2+1);
  vector<ll> pair2((n-1)/2+1);
  rep(i, (n-1)/2){
    if(i>0){
      pair1[i]=h[2*i+1]-h[2*i]+pair1[i-1];
    } else {
      pair1[i]=h[2*i+1]-h[2*i];
    }
  }
  for(int i=(n-1)/2-1; i>=0; i--){
    if(i<(n-1)/2-1){
      pair2[i]=h[2*i+2]-h[2*i+1]+pair2[i+1];
    } else {
      pair2[i]=h[2*i+2]-h[2*i+1];
    }
  }
  ll ans=INFll;
  rep(i, m){
    int wit=lower_bound(h.begin(), h.end(), w[i])-h.begin();
    ll cand=0;
    if(wit%2==0){
      cand+=h[wit]-w[i];
    } else {
      cand+=w[i]-h[wit-1];
    }
    if(wit/2==0){
      cand+=pair2[0];
    } else if(wit/2==(n-1)/2){
      cand+=pair1[wit/2-1];
    } else {
      cand+=pair1[wit/2-1]+pair2[wit/2];
    }
    ans=min(ans, cand);
  }
  cout << ans << endl;
  return 0;
}

#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
const int N = 1e8 + 10;
typedef long long ll;
int main(){
	int t,n,m;
	cin>>n>>m;
	int ans1=0,ans2=0;
	while(n){
		ans1+=n%10;
		n/=10;
	}
	while(m){
		ans2+=m%10;
		m/=10;
	}
	cout<<max(ans1,ans2)<<endl;
	return 0;
}

