#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL<<60;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(a)  (a).begin(),(a).end()



int main() {

ll N,M;
cin >> N >> M;

vector<ll> aa((1+N)/2);
vector<ll> bb((1+N)/2);

vector<ll> hh(N);
vector<ll> ww(M);

for(ll i=0;i<N;i++) cin >> hh[i];

for(ll i=0;i<M;i++) cin >> ww[i];

sort(ALL(hh));
ll ans=INF;

aa[0]=0;
for(ll i=1;i<(N+1)/2;i++){
aa[i]=aa[i-1]+hh[2*i-1]-hh[2*i-2];
}

for(ll i=(N-2)/2;i>=0;i--){
bb[i]=bb[i+1]+hh[2*i+2]-hh[2*i+1];
}

for(auto gg : ww){
ll x=lower_bound(ALL(hh),gg)-hh.begin();
 if(x & 1) x^=1;
 chmin(ans,aa[x/2]+bb[x/2]+abs(gg-hh[x]));


}

cout << ans << endl;








}
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0xccccccc;
const ll LINF = 0xcccccccccccccccLL;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}



//head

ll cc(ll x) {
  ll res = 1;
  while(x--) res *= 10;
  return res;
}
ll dd(ll x) {return x*x;}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll x = INT_MAX, xt = 0, y = INT_MAX, yt = 0, r = INT_MAX, rt = 0;
  string s;
  cin >> s;
  rep(i, s.size()) {
    if(s[i] != '.') continue;
    if(s[0] != '-') x = 1;
    else x = -1;
    s = s.substr(i+1);
    x *= stoi(s);
    xt = s.size();
    break;
  }
  if(x == INT_MAX) x = 0;
  cin >> s;
  rep(i, s.size()) {
    if(s[i] != '.') continue;
    if(s[0] != '-') y = 1;
    else y = -1;
    s = s.substr(i+1);
    y *= stoi(s);
    yt = s.size();
    break;
  }
  if(y == INT_MAX) y = 0;
  cin >> s;
  rep(i, s.size()) {
    if(s[i] != '.') continue;
    s = s.substr(0, i) + s.substr(i+1);
    r = stoi(s);
    rt = s.size()-i;
    break;
  }
  if(r == INT_MAX) r = stoi(s);
  int t = max({xt, yt, rt});
  x *= cc(t-xt);
  y *= cc(t-yt);
  r *= cc(t-rt);
  ll ans = 0;
  ll u = cc(t);
  //cout << P(x, y) << ' ' << P(r, t) << endl;
  for(ll z = -100010; z < 100010; z++) {
    ll now = z*u;
    //if(abs(y-now) > r) continue;
    //cout << z << endl;
    ll lb = -100010, ub = 1;
    while(ub-lb != 1) {
      ll mid = (lb+ub)>>1;
      if(dd(x-mid*u)+dd(y-now) <= r*r) ub = mid;
      else lb = mid;
    }
    int lef = ub;
    ub = 100010;
    lb = 0;
    while(ub-lb != 1) {
      ll mid = (lb+ub)>>1;
      if(dd(x-mid*u)+dd(y-now) <= r*r) lb = mid;
      else ub = mid;
    }
    ans += lb-lef+1;
  }
  cout << ans << endl;
}