#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main() {
	int n, m;
	cin >> n >> m;
	vector<int> h(n), w(m);
	rep(i, n) cin >> h[i];
	rep(i, m) cin >> w[i];
	sort(h.begin(), h.end());
	vector<int> l(n / 2 + 1), r(n / 2 + 1);
	for (int i = 0; i < n / 2; i++) l[i + 1] = l[i] + h[2 * i + 1] - h[2 * i];
	for (int i = n / 2; i > 0; i--) r[i - 1] = r[i] + h[2 * i] - h[2 * i - 1];
	int ans = 1e9;
	rep(i, m) {
		int itr = lower_bound(h.begin(), h.end(), w[i]) - h.begin();
		if (itr & 1) itr ^= 1;
		ans = min(ans, abs(w[i] - h[itr]) + l[itr / 2] + r[itr / 2]);
	}
	cout << ans << endl;
	return 0;
}
#include <bits/stdc++.h>
using namespace std;

using ull = unsigned long long;
using ll = long long;
using ld = long double;

const int mod = 1e9 + 7;
const double pi = acos(-1.0);
const int inf = INT_MAX;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int n, m;
	cin >> n >> m;

	vector<int> a(n), b(m);
	for (auto &i : a) cin >> i;
	for (auto &i : b) cin >> i;

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

	vector<int> diff1(n), diff2(n);
	for (int i = 1; i < n; i += 2) {
		diff1[i] = a[i] - a[i - 1];
	}
	for (int i = 3; i < n; i += 2) {
		diff1[i] += diff1[i - 2];
	}

	for (int i = n - 2; i >= 0; i -= 2) {
		diff2[i] = a[i + 1] - a[i];
	}

	for (int i = n - 4; i >= 0; i -= 2) {
		diff2[i] += diff2[i + 2];
	}

	int ans = INT_MAX;
	for (int x : b) {
		int i = upper_bound(a.begin(), a.end(), x) - a.begin();

		if (i % 2 != 0) {
			i--;
		}
		int val1 = (i == 0 ? 0 : diff1[i - 1]);
		int val2 = abs(a[i] - x);
		int val3 = (i + 1 == n ? 0 : diff2[i + 1]);
		ans = min(ans, val1 + val2 + val3);
	}
	cout << ans << '\n';
	return 0;
}