#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;
using pll = pair<ll, ll>;
ll mod = 998244353;
ll INF = 1000000000000;
void yorn(bool a) {
  if (a)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
ll gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
ll lcm(long long a, long long b) { return a / gcd(a, b) * b; }
template <class T>
void chmax(T &a, T b) {
  if (a < b) a = b;
}
template <class T>
void chmin(T &a, T b) {
  if (a > b) a = b;
}
template <class T>
class SGT {
 public:
  int n;
  vector<T> num;
  function<T(T, T)> f;
  T d;
  SGT(size_t n_, function<T(T, T)> f_, T d_) : f(f_), d(d_) {
    n = 1;
    while (n < n_) n *= 2;
    num = vector<T>(2 * n - 1, d);
  }
  void init(int sz, T a) {
    for (int i = 0; i < sz; i++) num[i + n - 1] = a;
    for (int i = n - 2; i >= 0; i--) num[i] = f(num[i * 2 + 1], num[i * 2 + 1]);
  }
  void init(vector<T> &a) {
    for (int i = 0; i < a.size(); i++) num[i + n - 1] = a[i];
    for (int i = n - 2; i >= 0; i--) num[i] = f(num[i * 2 + 1], num[i * 2 + 2]);
  }
  void update(int p, T a) {
    p += n - 1;
    num[p] = a;
    while (p) {
      p = (p - 1) / 2;
      num[p] = f(num[p * 2 + 1], num[p * 2 + 2]);
    }
  }
  void add(int p, T a) {
    p += n - 1;
    num[p] += a;
    while (p) {
      p = (p - 1) / 2;
      num[p] = f(num[p * 2 + 1], num[p * 2 + 2]);
    }
  }
  T query(int a, int b, int cur = 0, int l = 0, int r = -1) {
    if (r < 0) r = n;
    if (r <= a || b <= l) return d;
    if (a <= l && r <= b) return num[cur];
    T r1 = query(a, b, cur * 2 + 1, l, (l + r) / 2);
    T r2 = query(a, b, cur * 2 + 2, (l + r) / 2, r);
    return f(r1, r2);
  }
  T operator[](int p) { return num[p + n - 1]; }
};
int main() {
  V<ll> a(6);
  for (auto &i : a) cin >> i;
  int n;
  cin >> n;
  V<ll> b(n);
  for (auto &i : b) cin >> i;
  sort(a.begin(), a.end());
  a.push_back(INF);
  sort(b.begin(), b.end());
  SGT<ll> sgt(
      n, [](ll a, ll b) { return max(a, b); }, -INF);
  sgt.init(b);
  ll ans = INF;
  for (int i = 0; i < 6; i++) {
    for (int j = 0; j < n; j++) {
      ll l = b[j] - a[i];
      if (a[0] + l > b[0]) continue;
      ll sub = 0;
      for (int k = 0; k < 6; k++) {
        auto itl = lower_bound(b.begin(), b.end(), a[k] + l);
        auto itr = lower_bound(b.begin(), b.end(), a[k + 1] + l);
        chmax(sub, sgt.query(itl - b.begin(), itr - b.begin()) - a[k] - l);
      }
      chmin(ans, sub);
    }
  }
  cout << ans << endl;
}
