#include <bits/stdc++.h>
// #include <atcoder/all>
// using namespace atcoder;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << "\n"
#define COUTF(x) cout << setprecision(15) << (x) << "\n"
#define ENDL cout << "\n"
#define DF(x) x.erase(x.begin())
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define RSORT(x) sort(x.rbegin(), x.rend())
#define REVERSE(x) reverse(ALL(x))
#define MAX(x) *max_element(ALL(x))
#define MAXI(x) max_element(ALL(x)) - x.begin()
#define SUM(x) accumulate(ALL(x), 0ll)
#define COUNT(x, y) count(ALL(x), y);
#define ANS cout << ans << "\n"
#define YES cout << "YES\n";
#define NO cout << "NO\n";
#define Yes cout << "Yes\n";
#define No cout << "No\n";
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define LINE cerr << "[debug] line: " << __LINE__ << endl;
#define debug(x) cerr << "[debug] " << #x << ": " << x << endl;
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(z, v.size()) cerr << " " << v[z]; \
  cerr << endl;
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using mll = map<ll, ll>;
using qll = queue<ll>;
using P = pair<ll, ll>;
using vp = vector<P>;
using vs = vector<string>;

template <typename T>
inline istream& operator>>(istream& i, vector<T>& v) {
  rep(j, v.size()) i >> v[j];
  return i;
}

template <typename T1, typename T2>
inline istream& operator>>(istream& i, pair<T1, T2>& v) {
  return i >> v.first >> v.second;
}

constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

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;
}

signed main() {
  init();
  ll N, M;
  cin >> N >> M;
  vll H(N), W(M);
  cin >> H >> W;
  SORT(H);

  vp d(N);
  rep(i, N) {
    if (i == 0) continue;
    d[i] = d[i - 1];
    if (i % 2 == 1) {
      d[i].first += abs(H[i - 1] - H[i]);
    } else {
      d[i].second += abs(H[i - 1] - H[i]);
    }
  }

  ll ans = INF;
  rep(i, M) {
    ll lb = lower_bound(ALL(H), W[i]) - H.begin();
    if (lb % 2 == 1) lb--;
    ll a = abs(H[lb] - W[i]);
    if (lb != 0) a += d[lb - 1].first;
    if (lb != N - 1) a += (d[N - 1].second - d[lb].second);
    chmin(ans, a);
  }
  ANS;
  return 0;
}
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <cstdio>
#include <numeric>
#include <functional>

using namespace std;
typedef long long ll;

ll N, M;
vector<ll> H, W;

const ll INF = 1e17;
ll fpsum[200005];
ll bpsum[200005];

int main()
{
    ll ans = INF;

    cin >> N >> M;
    H.resize(N);
    W.resize(M);
    for (ll i = 0; i < N; i++)
    {
        cin >> H[i];
    }
    for (ll i = 0; i < M; i++)
    {
        cin >> W[i];
    }
    sort(H.begin(), H.end());
    for (ll i = 0; i < N - 2;i += 2)
    {
        fpsum[i/2 + 1] = H[i + 1] - H[i] + fpsum[i/2];
        bpsum[i/2 + 1] = H[i + 2] - H[i + 1] + bpsum[i/2];
    }
    /*
    for (ll i = 0; i < N - 2; i++)
    {
        cout << fpsum[i] << " ";
    }
    cout << endl;
    for (ll i = 0; i < N - 2; i++)
    {
        cout << bpsum[i] << " ";
    }
    cout << endl;
*/
    for (ll i = 0; i < M;i++)
    {
        auto it = upper_bound(H.begin(), H.end(), W[i]);
        ll idx = it - H.begin();
        ll tans;
        if (idx % 2 == 1)
        {
            tans = fpsum[idx / 2] + abs(W[i] - H[idx - 1]) + bpsum[N / 2] - bpsum[idx / 2];
        }
        else
        {
            tans = fpsum[idx / 2] + abs(W[i] - H[idx]) + bpsum[N / 2] - bpsum[idx / 2];
        }
        ans = min(ans, tans);
    }
    cout << ans << endl;
    return 0;
}