#include <bits/stdc++.h>
using namespace std;
int main(int argc, const char* argv[]) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  vector<int> a(6);
  for (auto& x : a) cin >> x;
  int n;
  cin >> n;
  vector<pair<int, int>> f(n * 6);
  for (int i = 0; i < n; ++i) {
    int t;
    cin >> t;
    for (int j = 0; j < 6; ++j) {
      f[i * 6 + j].first = t - a[j];
      f[i * 6 + j].second = i;
    }
  }
  sort(f.begin(), f.end());
  int cnt = 0;
  vector<int> st(n);
  vector<int> rght(6 * n, -1);
  for (int l = 0, r = -1; l < n * 6 && r < n * 6; ++l) {
    while (cnt != n && r < n * 6 - 1) {
      if (!st[f[++r].second]) {
        cnt++;
      }
      st[f[r].second]++;
    }
    if (cnt != n) break;
    rght[l] = r;
    st[f[l].second]--;
    if (st[f[l].second] == 0) cnt--;
  }
  int mn = 1e9;
  for (int i = 0; i < n * 6 && rght[i] != -1; ++i)
    mn = min(mn, f[rght[i]].first - f[i].first);
  cout << mn;
}
