#include <bits/stdc++.h>
#include <unistd.h>
//#include <atcoder/all>

#if __has_include(<local.h>)
#include <local.h>
#endif

using namespace std;
//using namespace atcoder;

typedef long long int LL;
typedef long long int LLint;

//Faster Program
#define endl "\n"

//Faster Coding
#define ED return
#define GET(a) int a;cin >> a
#define DGET(a) double a;cin >> a
#define SGET(a) string a;cin >> a
#define CGET(a) char a;cin >> a
#define PRINT(a) cout << a << "\n"
#define ANS(a,b) int a;cin >> a;cout << b << "\n"
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define SORT(vec) sort(vec.begin(),vec.end())
#define REV(vec) reverse(vec.begin(),vec.end())
#define ALL(x) (x).begin(),(x).end()

//As Function
#define UP(a,b) ((a+(b-1))/(b))
#define IPOW(x,y) (LL(pow(x,y)))

//Debug
#ifdef LOCAL_H
#define TEST cout << "OK\n"
#define DEBUG(a) a
#else
#define TEST
#define DEBUG(a)
#endif

#ifdef LOCAL_H
[[maybe_unused]]
#endif
const double PI = M_PI;
#ifdef LOCAL_H
[[maybe_unused]]
#endif
const int INF = int(999999999);
#ifdef LOCAL_H
[[maybe_unused]]
#endif
const LL LL_INF = LL(999999999999999999);
#ifdef LOCAL_H
[[maybe_unused]]
#endif
const long long MOD = int(1000000007);
#ifdef LOCAL_H
[[maybe_unused]]
#endif
const long long MOD_2 = int(998244353);

//Settings
#ifdef LOCAL_H
const bool DO_BENCHMARK = true;
#endif
const int DOUBLE_ACCURACY = 15;
const int RUN_SOLVE = 1;

#ifndef LOCAL_H
const bool DO_BENCHMARK = false;
#endif

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(DOUBLE_ACCURACY);
    for(int do_solve_time = 0;do_solve_time < RUN_SOLVE;do_solve_time++){
        void solve();
        if(DO_BENCHMARK){
            clock_t clock_start = clock();
            solve();
            clock_t clock_end = clock();
            const double time = static_cast<double>(clock_end-clock_start)/CLOCKS_PER_SEC*1000.0;
            cout << "\n------------------------------------\n" << time << "[ms]\n";
        }
        else solve();
    }
}

/*------------------------------↓ここからコード↓----------------------------------*/
void solve(){
    LL N, M;
    cin >> N >> M;
    vector<LL> H (N);
    vector<LL> W (M);
    for(LL i = 0;i < N;i++){
        cin >> H[i];
    }
    SORT(H);
    for(LL i = 0;i < M;i++){
        cin >> W[i];
    }
    SORT(W);
//    cout << endl;
//    for(LL i = 0;i < N;i++){
//        cout << H[i] << " ";
//    }
//    cout << endl;
//    for(LL i = 0;i < M;i++){
//        cout << W[i] << " ";
//    }
//    cout << endl;
    vector<LL> sum_before (N/2+1,0);
    vector<LL> sum_after (N/2+1,0);
    for(LL i = 0;i < N/2;i++){
        sum_before[i+1] = sum_before[i]+abs(H[i*2]-H[i*2+1]);
        sum_after[i+1] = sum_after[i]+abs(H[N-1-i*2]-H[N-2-i*2]);
    }

    LL ans = LL_INF;
    LL now = 0;
    for(LL i = 0;i < N/2+1;i++){
        while(now != M-1 && abs(H[i*2]-W[now]) >= abs(H[i*2]-W[now+1])){
            now++;
        }
//        cout << "CHANGE " << i*2 << "(" << H[i*2] << ")" << endl;
//        cout << " before = " << sum_before[i] << endl;
//        cout << " after = " << sum_after[N/2-i] << endl;
//        cout << " teacher = " << abs(H[i*2]-W[now]) << "(" << now << "," << W[now] << ")" << endl;
        ans = min(ans,sum_before[i]+sum_after[N/2-i]+abs(H[i*2]-W[now]));
    }
    cout << ans << endl;
    return;
}

#include <bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define pf(x) cout << (x) << endl
#define all(x) (x).begin(),(x).end()
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; }
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const char mc[4]={'U','L','D','R'};
const int max_e = 9000;
const int inf = 1000000000;
int mh[29][29],mv[29][29];

int dijkstra(vector<vector<int> > &m, pair<int, int> s){
    priority_queue<pair<int,pair<int,int> >, vector<pair<int,pair<int,int> > >, greater<pair<int,pair<int,int> > > > next;
    next.push(make_pair(0,s));
    while (!next.empty()) {
        int x = next.top().second.first,y = next.top().second.second;
        int p = next.top().first;
        next.pop();
        if(x > 0){
            if(chmin(m[x - 1][y], p + mv[x - 1][y])){
                next.push(make_pair(p + mv[x - 1][y], make_pair(x - 1, y)));
            }
        }
        if(x < 29){
            if(chmin(m[x + 1][y], p + mv[x][y])){
                next.push(make_pair(p + mv[x][y], make_pair(x + 1, y)));
            }
        }
        if(y > 0){
            if(chmin(m[x][y - 1], p + mv[x][y - 1])){
                next.push(make_pair(p + mv[x][y - 1], make_pair(x, y - 1)));
            }
        }
        if(y < 29){
            if(chmin(m[x][y + 1], p + mv[x][y])){
                next.push(make_pair(p + mv[x][y], make_pair(x, y + 1)));
            }
        }
    }
    return 0;
}

string restore(vector<vector<int> > &m, int x, int y){
    string root = "";
    int s = 0;
    while (m[x][y] != 0) {
        ++s;
        int next_x = x,next_y = y,p = m[x][y];
        rep0(i, 4)if(chmin(p, m[min(max(0,x + dx[i]),29)][min(max(0,y + dy[i]),29)])){
            next_x = x + dx[i];
            next_y = y + dy[i];
            if(s != root.size())root.push_back(mc[i]);
            else root[s - 1] = mc[i];
        }
        x = next_x;
        y = next_y;
    }
    reverse(all(root));
    return root;
}

int update(string s, int p, int x, int y){
    rep0(i, s.size()){
        if(s[i] == 'U'){
            mv[x - 1][y] = (mv[x - 1][y] + p + 1) / 2;
            x--;
        }else if(s[i] == 'D'){
            mv[x][y] = (mv[x][y] + p + 1) / 2;
            x++;
        }else if(s[i] == 'R'){
            mh[x][y] = (mh[x][y] + p + 1) / 2;
            y++;
        }else{
            mh[x][y - 1] = (mh[x][y - 1] + p + 1) / 2;
            y--;
        }
    }
    return 0;
}

//modを確認すること
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    rep0(i, 30)rep0(j, 30){
        //mh[i][j] = max_e;
        //mv[i][j] = max_e;
        mh[i][j] = rand() % 8000 + 1000;
        mv[i][j] = rand() % 8000 + 1000;
    }
    
    rep0(i, 1000){
        vector<vector<int> > m(30,vector<int>(30,inf));
        int sx,sy,gx,gy,p;
        string s = "";
        cin >> sx >> sy >> gx >> gy;
        m[sx][sy] = 0;
        
        dijkstra(m, make_pair(sx, sy));
        string ans = restore(m, gx, gy);
        
        pf(ans);
        
        cin >> p;
        update(ans, int((p + ans.size() - 1) / ans.size()), sx, sy);
    }
    return 0;
}
