#include <bits/stdc++.h>
using namespace std;
template <typename T>
void read(T &x) {
  x = 0;
  char ch = getchar();
  long long f = 1;
  while (!isdigit(ch)) {
    if (ch == '-') f *= -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - 48;
    ch = getchar();
  }
  x *= f;
}
int n, m;
struct p {
  int x, v;
};
int a[6];
p b[600010];
bool cmp(const p &a, const p &b) { return a.v < b.v; }
int fst[600010];
int cnt[100010];
void init();
int main() {
  int x;
  int mi = 0x3f3f3f3f;
  for (int i = 0; i < 6; ++i) scanf("%d", &a[i]);
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &x);
    for (int j = 0; j < 6; ++j) b[++m] = {i, x - a[j]};
  }
  sort(b + 1, b + 1 + m, cmp);
  init();
  for (int i = 1; i <= m; ++i) {
    if (fst[i] == 0x3f3f3f3f) break;
    mi = min(mi, b[fst[i]].v - b[i].v);
  }
  printf("%d", mi);
  return 0;
}
void init() {
  int x = 0;
  int sum = 0;
  memset(fst, 0x3f, sizeof(fst));
  while (x < m) {
    ++x;
    if (++cnt[b[x].x] == 1) ++sum;
    if (sum == n) break;
  }
  fst[1] = x;
  for (int i = 2; i <= m; ++i) {
    if (--cnt[b[i - 1].x] == 0) --sum;
    if (sum < n) {
      while (x < m) {
        ++x;
        if (++cnt[b[x].x] == 1) ++sum;
        if (sum == n) break;
      }
    }
    if (sum < n) return;
    fst[i] = x;
  }
}
