#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
unsigned seed = chrono::system_clock::now().time_since_epoch().count();
mt19937 eng(seed);
long long random2() { return (1ll << 31ll) * eng() + eng(); }
long long n, m, k, q, T;
const long long big = 1000000007;
const long long big2 = 1000000009;
const long long mod = 998244353;
const int MAXN = 200001;
struct Tree {
  static constexpr long long unit = -big * big;
  long long f(long long a, long long b) { return max(a, b); }
  vector<long long> s;
  int n;
  Tree(int n = 0, long long def = unit) : s(2 * n, def), n(n) {}
  void update(int pos, long long val) {
    for (s[pos += n] = val; pos /= 2;) s[pos] = f(s[pos * 2], s[pos * 2 + 1]);
  }
  long long query(int b, int e) {
    long long ra = unit, rb = unit;
    for (b += n, e += n; b < e; b /= 2, e /= 2) {
      if (b % 2) ra = f(ra, s[b++]);
      if (e % 2) rb = f(s[--e], rb);
    }
    return f(ra, rb);
  }
};
vector<long long> A(6);
vector<long long> L, R;
vector<long long> B;
vector<long long> C, kind, ind;
;
bool comp(long long i, long long j) { return C[i] < C[j]; }
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long a, b, c;
  for (int c1 = 0; c1 < (6); ++c1) {
    cin >> a;
    A[c1] = a;
  }
  sort(A.begin(), A.end());
  cin >> n;
  for (int c1 = 0; c1 < (n); ++c1) {
    cin >> a;
    B.push_back(a);
    for (int c2 = 0; c2 < (6); ++c2) {
      C.push_back(B[c1] - A[c2]);
      kind.push_back(c1);
      ind.push_back((int)(ind).size());
    }
  }
  sort(ind.begin(), ind.end(), comp);
  Tree ST(n, big * big);
  long long ans = big * big;
  for (auto& i : ind) {
    long long x = C[i];
    ST.update(kind[i], -x);
    long long mi = -ST.query(0, n);
    ans = min(ans, x - mi);
  }
  cout << ans << "\n";
  return 0;
}
