#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, start, n) for (ll i = (ll)(start); i < (ll)(n); ++i)
static const ll INFTY = 1L << 62L;
ll solver(vector<ll> &h, ll n, ll *w, ll m)
{
    ll j, k, answer = INFTY, ans;
    sort(h.begin(), h.end());
    //r1: 0,h[1]-h[0],h[3]-h[2],h[5]-h[4],...,h[n-2]-h[n-3]要素数は(n-1)/2+1
    //r2: 0,h[2]-h[1],h[4]-h[3],h[6]-h[5],...,h[n-1]-h[n-2]
    //r1[k]=r1[k-1]+h[2k-1]-h[2k-2],k>=1
    //r2[k]=r2[k-1]+h[2k]-h[2k-1],k>=1
    vector<ll> r1, r2;
    r1.push_back(0);
    r2.push_back(0);
    rep(i, 0, n - 1)
    {
        if (i % 2 == 0)
            r1.push_back(r1.back() + h[i + 1] - h[i]);
        else
            r2.push_back(r2.back() + h[i + 1] - h[i]);
    }
    rep(i, 0, m)
    {
        ans = 0;
        j = lower_bound(h.begin(), h.end(), w[i]) - h.begin();
        //jが偶数のとき，h[1]-h[0],...,h[j-1]-h[j-2],h[j]-w[i],h[j+2]-h[j+1],...
        if (j % 2 == 0)
        {
            ans += r1[j / 2]; //h[1]-h[0],...,h[j-1]-h[j-2]
            ans += h[j] - w[i];
            ans += r2.back() - r2[j / 2]; //h[j]-h[j-1]は含まれない
        }
        //jが奇数のとき
        else
        {
            ans += r1[(j - 1) / 2]; //h[1]-h[0],...,h[j-2]-h[j-3]
            ans += w[i] - h[j - 1];
            ans += r2.back() - r2[(j - 1) / 2]; //h[j]+h[j+1],...
        }

        answer = min(ans, answer);
    }
    return answer;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, m;
    cin >> n >> m;
    vector<ll> h(n);
    ll w[m];
    rep(i, 0, n) cin >> h[i];
    rep(i, 0, m) cin >> w[i];
    cout << solver(h, n, w, m) << endl;
}
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string(string(s)); }
string to_string(bool b) { return to_string(int(b)); }
string to_string(vector<bool>::reference b) { return to_string(int(b)); }
string to_string(char b) { return "'" + string(1, b) + "'"; }
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A>
string to_string(A v) {
	string res = "{";
	for (const auto& x : v) res += (res == "{" ? "" : ", ") + to_string(x);
	return res + "}";
}
void debug() { cerr << endl; }
template <typename Head, typename... Tail>
void debug(Head H, Tail... T) {
	cerr << " " << to_string(H);
	debug(T...);
}
#define db(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__)
#else
#define db(...) 42
#endif
typedef long long ll;
typedef long double ld;
int main() {
	int n, m;
	scanf("%d%d", &n, &m);
	vector<pair<int, int>> H(n);
	for (int i = 0; i < n; ++i) {
		scanf("%d", &H[i].first);
	}
	for (int i = 0; i < m; ++i) {
		int w;
		scanf("%d", &w);
		H.push_back({w, 1});
	}
	sort(H.begin(), H.end());
	int las = 0;
	ll s = 0;
	vector<pair<ll, int>> suf(H.size() + 1);
	for (int i = (int)H.size() - 1; i >= 0; --i) {
		if (H[i].second == 0) {
			if (las == 0) las = H[i].first;
			else {
				s += las - H[i].first;
				las = 0;
			}
			suf[i] = {s, las};
		} else suf[i] = suf[i + 1];
	}
	las = s = 0;
	ll ans = LLONG_MAX;
	for (int i = 0; i < H.size(); ++i) {
		int v = H[i].first;
		int t = H[i].second;
		if (t == 1) {
			ll sum = suf[i + 1].first + s;
			if (suf[i + 1].second) {
				sum += suf[i + 1].second - v;
			} else {
				sum += v - las;
			}
			ans = min(ans, sum);
		} else {
			if (las == 0) las = v;
			else {
				s += v - las;
				las = 0;
			}
		}
	}
	printf("%lld\n", ans);
}
