#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long maxN = 1e5 + 5;
const long long N = 1e6;
int n;
int a[8], b[maxN];
int d[maxN][8];
vector<int> v;
int id[maxN];
priority_queue<pair<long long, long long>, vector<pair<long long, long long> >,
               greater<pair<long long, long long> > >
    p;
int main() {
  ios_base::sync_with_stdio(0);
  for (long long i = 1; i <= 6; i++) cin >> a[i];
  sort(a + 1, a + 1 + 6, greater<int>());
  cin >> n;
  for (long long i = 1; i <= n; i++) cin >> b[i];
  sort(b + 1, b + 1 + n);
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= 6; j++) {
      d[i][j] = b[i] - a[j];
      v.push_back(d[i][j]);
    }
  }
  for (long long i = 1; i <= n; i++) id[i] = 1;
  int cuoi = v[0];
  for (long long i = 1; i <= n; i++)
    p.push(pair<long long, long long>(d[i][1], i)), cuoi = max(cuoi, d[i][1]);
  sort(v.begin(), v.end());
  int res = 1e9 + 5;
  int pret = -1;
  for (auto t : v) {
    if (t == pret) continue;
    pret = t;
    bool kt = 1;
    while (1) {
      pair<long long, long long> tmp = p.top();
      if (tmp.first < t) {
        p.pop();
        long long i = tmp.second;
        while (id[i] <= 6 && d[i][id[i]] < t) id[i]++;
        if (id[i] > 6) {
          kt = 0;
          break;
        }
        cuoi = max(cuoi, d[i][id[i]]);
        p.push(pair<long long, long long>(d[i][id[i]], i));
      } else {
        break;
      }
    }
    if (kt == 1)
      res = min(res, cuoi - t);
    else
      break;
  }
  cout << res;
  return 0;
}
