#include <bits/stdc++.h>
using namespace std;
mt19937 bruh(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rofl(chrono::steady_clock::now().time_since_epoch().count());
const int N = 1e5 + 2;
const int M = 1e5;
const int mod = 0;
const int inf = 2e9 + 3;
const long long INF = 1e9 + 200;
const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
void files() {
  freopen(".in", "r", stdin);
  freopen(".out", "w", stdout);
}
long long a[10], b[N], d[N][10], was[N], n;
set<int> s;
vector<pair<long long, long long> > v;
int main() {
  for (int i = 1; i <= 6; ++i) scanf("%lld", &a[i]);
  scanf("%lld", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%lld", &b[i]);
    for (int j = 1; j <= 6; ++j) {
      d[i][j] = b[i] - a[j];
      v.push_back({d[i][j], i});
    }
    sort(d[i] + 1, d[i] + 7);
  }
  sort(v.begin(), v.end());
  int r = -1;
  long long ans = INF;
  int c = 0;
  int pos = 0;
  for (int l = 0; l < (int)v.size(); ++l) {
    if (c != n)
      while (r + 1 < (int)v.size() && c + (was[v[r + 1].second] == 0) <= n) {
        ++r;
        c += (was[v[r].second] == 0);
        was[v[r].second]++;
        if (c == n) break;
      }
    if (c == n) {
      ans = min(ans, v[r].first - v[l].first);
    }
    was[v[l].second]--;
    c -= (was[v[l].second] == 0);
  }
  printf("%lld", ans);
}
