#include <bits/stdc++.h>
using namespace std;
template <class T>
void Phc(const T &X) {
  printf("%lld\n", X);
}
template <class T>
void Pkg(const T &X) {
  printf("%lld ", X);
}
inline long long read() {
  char ch = getchar();
  long long x = 0, f = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while ('0' <= ch && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int fastmi(int i, int b, const int &p) {
  long long ans = 1, now = i;
  while (b) {
    if (b & 1) ans = now * ans % p;
    now = now * now % p;
    b >>= 1;
  }
  return ans;
}
int ra(int low, int hi) { return rand() % (hi - low + 1) + low; }
void assi() {
  freopen("1.in", "r", stdin);
  freopen("1.out", "w", stdout);
}
const int inf = 1e9 + 7;
const int N = 2e5 + 7;
pair<int, int> Q[N * 6];
int b[N][8], a[N];
bool mmp(pair<int, int> X, pair<int, int> Y) {
  return b[X.first][X.second] < b[Y.first][Y.second];
}
int main() {
  for (int i = 1; i <= 6; i++) scanf("%d", &a[i]);
  sort(a + 1, a + 1 + 6);
  int n = read();
  for (int i = 1; i <= n; i++) {
    int x = read();
    for (int j = 1; j <= 6; j++) b[i][j] = x - a[7 - j];
    b[i][7] = inf;
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= 6; j++) Q[i * 6 - 6 + j] = make_pair(i, j);
  int ans = inf;
  sort(Q + 1, Q + 1 + 6 * n, mmp);
  int mx = 0;
  for (int i = 1; i <= n; i++) mx = max(mx, b[i][1]);
  for (int i = 1; i <= 6 * n;) {
    int x = b[Q[i].first][Q[i].second];
    if (mx == inf) break;
    ans = min(mx - x, ans);
    while (b[Q[i].first][Q[i].second] == x) {
      mx = max(b[Q[i].first][Q[i].second + 1], mx);
      i++;
    }
  }
  printf("%d\n", ans);
}
