#pragma region Macros
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define REP2(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; ++i)
#define REP3(i, l, r) for (int i = (l), i##_len = (int)(r); i < i##_len; ++i)
#define GET_MACRO_REP(_1, _2, _3, NAME, ...) NAME
#define REP(...) GET_MACRO_REP(__VA_ARGS__, REP3, REP2) (__VA_ARGS__)
#define RREP2(i, n) for (int i = (n - 1); i >= 0; --i)
#define RREP3(i, l, r) for (int i = (r - 1), i##_len = (l); i >= i##_len; --i)
#define GET_MACRO_RREP(_1, _2, _3, NAME, ...) NAME
#define RREP(...) GET_MACRO_REP(__VA_ARGS__, RREP3, RREP2) (__VA_ARGS__)
#define IN(type, n) type n; cin >> n
#define INALL(v) for (auto &e : v) { cin >> e; }
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

#ifdef _DEBUG
#define DEBUG(x) cout << #x << ": " << x << endl
#else
#define DEBUG(x)
#endif

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; }
void yes() { cout << "Yes" << endl; }
void no() { cout << "No" << endl; }
#pragma endregion

ll s2ll(string num, ll base = 10000) {
  ll ans = 0;
  size_t dot_idx = 0;
  bool is_negative = false;

  for (size_t idx = 0; idx < num.size(); ++idx) {
    if (num.at(idx) == '.') {
      dot_idx = idx;
      break;
    } else if (num.at(idx) == '-') {
      is_negative = true;
    } else {
      ans *= 10;
      ans += num.at(idx) - '0';
    }
  }
  ans *= base;

  if (dot_idx != 0) {
    for (int i = 1; base > 1; ++i) {
      if (dot_idx + i >= num.size()) break;
      base /= 10;
      ans += (num.at(dot_idx + i) - '0') * base;
    }
  }

  if (is_negative) ans *= -1;

  return ans;
}

ll floor_base(ll num, ll base = 10000) {
  return (num / base) * base;
}

int main() {
  IN(string, X);
  ll xl = abs(s2ll(X));
  IN(string, Y);
  ll yl = abs(s2ll(Y));
  IN(string, R);
  ll rl = s2ll(R);

  if (xl - rl <= 0) xl += floor_base(rl - xl + 10000);
  if (yl - rl <= 0) yl += floor_base(rl - yl + 10000);

  ll ans = 0;
  for (ll pos_x = floor_base(xl + rl); pos_x >= xl - rl; pos_x -= 10000) {
    ll len_x = pos_x - xl;
    ll len_y;
    if (len_x == 0) len_y = rl;
    else len_y = (ll)sqrtl(rl * rl - len_x * len_x);
    ans += (yl + len_y) / 10000 - (yl - len_y - 1) / 10000;
  }

  cout << ans << endl;

  return 0;
}

#include <bits/stdc++.h>

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

const int N = 2e5 + 5;
ll h[N], w;
ll l[N], r[N];
int n, m;
ll ans = LLONG_MAX;
set<int> st;

int main() {
    cin >> n >> m;
    for (int i = 0; i < n; ++i) {
        cin >> h[i];
    }
    sort(h, h + n);
    ll sum = 0;
    for (int i = 0; i < n; i += 2) {
        l[i] = sum;
        sum += abs(h[i + 1] - h[i]);
    }
    sum = 0;
    for (int i = n - 1; i >= 0; i -= 2) {
        r[i] = sum;
        sum += abs(h[i] - h[i - 1]);
    }
    for (int i = 0; i < m; ++i) {
        cin >> w;
        st.insert(w);
    }
    st.insert(INT_MAX);
    st.insert(INT_MIN);
    for (int i = 0; i < n; i += 2) {
        auto it = st.lower_bound(h[i]);
        ll mi = abs(*it - h[i]);
        --it;
        mi = min(mi, abs(*it - h[i]));

        ll res = l[i] + r[i] + mi;
        ans = min(ans, res);
    }
    cout << ans << endl;

    return 0;
}
