#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<unordered_map>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 100000000001
#define LLINF 9223372036854780LL
#define mod 998244353
//#define mod 1000000007
//priority_queue<int,vector<int>, greater<int> > q2;

ll modpow(ll a, ll n = mod - 2) {
	ll r = 1;
	while (n) r = r * ((n % 2) ? a : 1) % mod, a = a * a%mod, n >>= 1;
	return r;
}

long long modinv(long long a) {
	return modpow(a, mod - 2);
}
struct LazySegmentTree {
private:
	int n;
	vector<ll> node, lazy;

public:
	LazySegmentTree(vector<ll> v) {
		int sz = (int)v.size();
		n = 1; while (n < sz) n *= 2;
		node.resize(2 * n - 1);
		lazy.resize(2 * n - 1, 0);

		for (int i = 0; i < sz; i++) node[i + n - 1] = v[i];
		for (int i = n - 2; i >= 0; i--) node[i] = (node[i * 2 + 1] + node[i * 2 + 2]) % mod;
	}

	void eval(int k, int l, int r) {
		if (lazy[k] != 0) {
			node[k] += lazy[k];
			node[k] %= mod;
			if (r - l > 1) {
				lazy[2 * k + 1] += lazy[k] * modinv(2);
				lazy[2 * k + 2] += lazy[k] * modinv(2);
				lazy[2 * k + 1] %= mod;
				lazy[2 * k + 2] %= mod;
			}
			lazy[k] = 0;
		}
	}

	void add(int a, int b, ll x, int k = 0, int l = 0, int r = -1) {
		if (r < 0) r = n;
		eval(k, l, r);
		if (b <= l || r <= a) return;
		if (a <= l && r <= b) {
			lazy[k] += (r - l) * x;
			lazy[k] %= mod;
			eval(k, l, r);
		}
		else {
			add(a, b, x, 2 * k + 1, l, (l + r) / 2);
			add(a, b, x, 2 * k + 2, (l + r) / 2, r);
			node[k] = (node[2 * k + 1] + node[2 * k + 2]) % mod;
		}
	}

	ll getsum(int a, int b, int k = 0, int l = 0, int r = -1) {
		if (r < 0) r = n;
		eval(k, l, r);
		if (b <= l || r <= a) return 0;
		if (a <= l && r <= b) return node[k];
		ll vl = getsum(a, b, 2 * k + 1, l, (l + r) / 2);
		ll vr = getsum(a, b, 2 * k + 2, (l + r) / 2, r);
		return (vl + vr) % mod;
	}
};

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N; cin >> N;
	int M; cin >> M;
	VI H(N), W(M);
	REP(i, N)cin >> H[i];
	REP(i, M)cin >> W[i];
	SORT(H);
	int ans = LLINF;
	VI sum(N + 2, 0), sum1(N + 2, 0);
	for (int i = 0; i < N; i += 2) {
		if (i + 1 >= N)break;
		sum[i / 2 + 1] += abs(H[i] - H[i + 1]) + sum[i / 2];
	}
	int j = 1;
	for (int i = N - 1; i >= 0; i -= 2) {
		if (i - 1 < 0)break;
		sum1[j] += abs(H[i] - H[i - 1]) + sum1[j - 1];
		j++;
	}
	REP(i, M) {
		int it = LB(H, W[i]) - H.begin();
		int itt = N - it;
		int cnt = sum[it / 2] + sum1[itt / 2];
		//cout << it << " " << sum[it / 2] << " " << sum1[itt / 2] << endl;
		if (it % 2) {
			cnt += abs(W[i] - H[it - 1]);
		}
		else {
			cnt += abs(W[i] - H[it]);
		}
		chmin(ans, cnt);
	}

	cout << ans << endl;
	/*
	int N, Q; cin >> N >> Q;

	while (Q--) {
		int t, x; cin >> t >> x;

	}
	*/
	return 0;
}



#include<iostream>
using namespace std;
typedef long long ll;
int MOD = 998244353;
ll ksm(ll a,ll b,ll mod){
    ll ans = 1;
    while(b>0){
        if(b&1) ans = ans * a % mod;
        a = a * a % mod;
        b >>=1;
    }
    return ans;
}
int main(){
    ll N,M,K;
    cin >> N >> M >> K;
    ll ans = 0;
    for(int i = 1; i <= K; ++i){
        if(M == 1)
            ans+=((ksm(i,N,MOD) - ksm(i-1,N,MOD) + MOD)%MOD);
        else if(N==1){
            ans+=((ksm(i,N,MOD) - ksm(i-1,N,MOD) + MOD)%MOD)*((ksm(K-i+1,M,MOD) - ksm(K-i,M,MOD)+MOD)%MOD);
        }
        else
            ans+=((ksm(i,N,MOD) - ksm(i-1,N,MOD) + MOD)%MOD)*(ksm(K-i+1,M,MOD)%MOD);

        ans%=MOD;
    }
    cout << ans << endl;
    return 0;
}