#include <bits/stdc++.h>
using namespace std;
const long long inf = 0x3f3f3f3f, N = 3e5;
struct RMQ {
  vector<long long> t;
  long long n;
  RMQ(long long n) : n(n) { t.resize(n << 1); }
  void build(long long a[]) {
    for (long long i = 0; i < n; i++) t[n + i] = a[i];
    for (long long i = n - 1; i > 0; --i) t[i] = min(t[i << 1], t[i << 1 | 1]);
  }
  void modify(long long p, long long v) {
    for (t[p += n] = v; p > 1; p >>= 1) t[p >> 1] = min(t[p], t[p ^ 1]);
  }
  long long query(long long l, long long r) {
    long long res = inf;
    for (l += n, r += n + 1; l < r; l >>= 1, r >>= 1) {
      if (l & 1) res = min(res, t[l++]);
      if (r & 1) res = min(res, t[--r]);
    }
    return res;
  }
};
int32_t main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  vector<long long> a(6);
  for (long long &x : a) cin >> x;
  long long n;
  cin >> n;
  vector<long long> v(n);
  for (long long &x : v) cin >> x;
  RMQ ST(n + 7);
  vector<vector<long long> > d(n);
  map<long long, vector<long long> > mp;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < 6; j++) d[i].push_back(v[i] - a[j]);
    sort(d[i].begin(), d[i].end());
    for (long long x : d[i]) {
      mp[-x].push_back(i);
    }
    ST.modify(i + 1, d[i].back());
  }
  long long ans = 1e10;
  for (auto [x, vv] : mp) {
    long long y = -x;
    ans = min(ans, y - ST.query(1, n));
    for (long long i : vv) {
      d[i].pop_back();
      if (d[i].empty()) {
        cout << ans << endl;
        return 0;
      }
      ST.modify(i + 1, d[i].back());
    }
  }
}
