#include <algorithm>
#include <iostream>
#include <iterator>
#include <vector>

using namespace std;

int main() {
    int n, m;
    cin >> n >> m;

    vector<long long> h(n);
    for (int i = 0; i < n; i++) {
        cin >> h[i];
    }

    vector<long long> w(m);
    for (int i = 0; i < m; i++) {
        cin >> w[i];
    }

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

    vector<long long> p(n / 2 + 1, 0);
    for (int i = 0; i < n - 1; i += 2) {
        p[i / 2 + 1] = h[i + 1] - h[i];
        p[i / 2 + 1] += p[i / 2];
    }

    vector<long long> q(n / 2 + 1, 0);
    for (int i = 0; i < n - 1; i += 2) {
        q[i / 2 + 1] = h[n - i - 1] - h[n - i - 2];
        q[i / 2 + 1] += q[i / 2];
    }

    vector<long long> res(m);
    for (int i = 0; i < m; i++) {
        int j = distance(h.begin(), lower_bound(h.begin(), h.end(), w[i]));
        res[i] = p[j / 2] + q[n / 2 - j / 2] + (j % 2 == 0 ? h[j] - w[i] : w[i] - h[j - 1]);
    }

    cout << *min_element(res.begin(), res.end()) << endl;
}

/*
   Three things which are very important --
   Violence - Speed - Momentum
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define oset tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define setbits(x)      __builtin_popcountll(x)
#define leadzero(x)     __builtin_clz(x)
#define trailzero(x)    __builtin_ctz(x)
#define bitsparity(x)   __builtin_parity(x)
#define mod             1000000007
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll              long long 
//#define pre(y,x)        fixed<<setprecision(y)<<x
#define dbg1(x)         cerr << "|" << #x << ": " << (x) << "|\n";
#define dbg2(x,y)       cerr << "|" << #x << ": " << (x) << "|" << #y << ": " << (y) << "|\n";
#define dbg3(x,y,z)     cerr << "|" << #x << ": " << (x) << "|" << #y << ": " << (y) << "|" << #z << ": " << (z) << "|\n";
#define ff              first
#define ss              second
#define pb              push_back
#define eb              emplace_back
#define popb            pop_back
#define endl            '\n'
#define all(v)          v.begin(), v.end()
#define sz(x)           ((int)((x).size()))
typedef pair<int, int> pii; 
typedef pair<ll, ll> pll; 
typedef pair<string, string> pss; 
typedef vector<int> vi; 
typedef vector<vi> vvi; 
typedef vector<pii> vii;
typedef vector<pll> vll; 
typedef vector<ll> vl; 
typedef vector<vl> vvl;
typedef vector<string> vs;
ll power(ll a, ll b) {
	if(b<0) return 1;
	ll res=1;
	while(b) {
		if(b&1) 
			res = (res*a)%mod;
		a = (a*a)%mod;
		b >>= 1;
	}
	return res;
}
bool ispoweroftwo(ll x){ return (x&&!(x&(x-1)));}
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
const int inf = 1e9;
//integer to char always remember (char+'0')
const double pi = acos(-1);
const ll INF = 1e18;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
const int maxN = 2e5+9;

int main() {
	FIO;
	ll n, m;
	cin >> n >> m;
	vector<ll> h(n), w(m);
	for(int i=0; i<n; ++i) {
		cin >> h[i];
	}
	for(int i=0; i<m; ++i) {
		cin >> w[i];
	}	
	sort(all(h));
	vector<ll> pre(n+1, 0), suf(n+1, 0);
	for(int i=0; i+1<n; i+=2) {
		pre[i] = (i==0?0:pre[i-1]) + abs(h[i+1]-h[i]);
		pre[i+1] = pre[i];
	}
	for(int 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=INF;
	for(ll i=0; i<m; ++i) {
		auto it = lower_bound(all(h), w[i]);
		
		if(it == h.begin()) {
			ans = min(ans, suf[1] + abs(h[0]-w[i]));
			
		}
		else if(it == h.end()) {
			ans = min(ans, pre[n-2] + abs(h[n-1]-w[i]));
		}
		else {
			ll j = it-h.begin();
			if(j%2==0) {
				ans = min(ans, pre[j-1] + abs(h[j]-w[i]) + suf[j+2]);
			}
			else {
				ans = min(ans, (j-2>=0?pre[j-2]:0) + abs(h[j-1]-w[i]) + suf[j+1]);
			}
		}
		
	}
	cout << ans;	
	return 0;	
}
/*

*/