#include<bits/stdc++.h>

using namespace std;
using ll = long long;
using pint = pair<int,int>;
// #include"debug.hpp"
const int INF = 1e9;

vector<vector<int>> lcs(vector<int> s, vector<int> t) {
    int n = s.size(), m = t.size();


    vector<vector<int>> dp(n + 1, vector<int>(m + 1, INF)); //dp[i][j] := s[i - 1], t[j - 1]まで処理し終えたときの最小コスト
	for(int i = 0; i <= n; i++) {
		for(int j = 0; j < m; j++) {

			if(i == 0) {
				dp[i][j] = j;
			}
			if(j == 0) {
				dp[i][j] = i;
			}
		}
	}


    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++) {

			dp[i + 1][j + 1] = min({dp[i][j] + 1,dp[i + 1][j] + 1, dp[i][j + 1] + 1, dp[i + 1][j + 1]});

			if(s[i] == t[j]) {
				dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j]);
			}

        }
    }
    return dp;
}

int main()
{
	int N, M; cin >> N >> M;
	vector<int> A(N), B(M);
	for(int i = 0; i < N; i++) cin >> A[i];
	for(int i = 0; i < M; i++) cin >> B[i];
	vector<vector<int>> dp = lcs(A, B);

	cout << dp[N][M] << endl;


}
#include <bits/stdc++.h>
using namespace std;

#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(x) x.begin(),x.end()
typedef long long ll;
ll mod = 1000000007;
ll inf = 1e18;
int main(){

    int n,m;
    cin >> n >> m;
    vector<int> h(n),w(m);
    vector<int> dist(n-1);
    vector<int> teacher(n);
    ll sum=0,ans=mod;

    

    rep(i,n) cin >> h[i];
    rep(i,m) cin >> w[i];

    sort(all(h));
    sort(all(w));

    if(n==1){
        int a=mod;
        rep(i,m){
            a=min(a,abs(w[i]-h[0]));
        }
        cout << a << endl;
        return 0;
    }

    for(int i=0; i<n-1; i+=2){
        if(i==0) dist[i]=h[i+1]-h[i];
        else dist[i]=h[i+1]-h[i]+dist[i-2];
    }
    for(int i=n-2; i>0; i-=2){
        if(i==n-2) dist[i]=h[i+1]-h[i];
        else dist[i]=h[i+1]-h[i]+dist[i+2];
    }

    for(int i=0; i<n; i+=2){
        if(i==0) teacher[i]=dist[i+1];
        else if(i==n-1) teacher[i]=dist[i-2];
        else teacher[i]=dist[i-2]+dist[i+1];
    }

    rep(i,m){
        int key=w[i];
        auto iter=lower_bound(all(h),key);
        int x=iter-h.begin();
        if(x%2) x--;
        sum=abs(key-h[x])+teacher[x];
        // cout << sum << endl;
        ans=min(ans,sum);
        sum=0;
    }

    cout << ans << endl;

       
    return 0;
}