#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000009;
const long long INFL = 1000000000000000009;
const long double EPS = 0.000001;
const long long MOD = 1000000009;
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  vector<int> a(6);
  for (int i = 0; i < 6; ++i) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  int n;
  cin >> n;
  vector<int> b(n);
  for (int i = 0; i < n; ++i) {
    cin >> b[i];
  }
  sort(b.begin(), b.end());
  vector<int> p(n * 6);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < 6; ++j) {
      p[6 * i + j] = b[i] - a[j];
    }
  }
  sort(p.begin(), p.end());
  vector<pair<int, int> > ans(6);
  ans[5] = {0, n - 1};
  int delta = INF;
  for (int li = 0; (li < p.size()) && (p[li] <= b[0] - a[0]); ++li) {
    for (int i = 0; i < 6; ++i) {
      while (ans[i].first < n && b[ans[i].first] - a[i] < p[li]) {
        if (i > 0 && ans[i - 1].second < ans[i].first) {
          ans[i - 1].second++;
        }
        ans[i].first++;
      }
    }
    int l = INF, r = 0;
    bool flag = false;
    for (int i = 0; i < 6; ++i) {
      if (ans[i].first < n && ans[i].second < n) {
        flag = true;
        l = min(l, b[ans[i].first] - a[i]);
        r = max(r, b[ans[i].second] - a[i]);
      }
    }
    if (flag) {
      delta = min(delta, r - l);
    }
  }
  cout << delta;
  return 0;
}
