#include <bits/stdc++.h>
using namespace std;
long long gi() {
  char cc = getchar();
  long long cn = 0, flus = 1;
  while (cc < '0' || cc > '9') {
    if (cc == '-') flus = -flus;
    cc = getchar();
  }
  while (cc >= '0' && cc <= '9') cn = cn * 10 + cc - '0', cc = getchar();
  return cn * flus;
}
const long long inf = 1e15;
const long long N = 2e5 + 5;
const long long M = 1e6 + 5;
long long n, a[N], b[N], cnt[N];
long long top, Col, f[N][10];
struct node {
  long long c, w;
} g[M];
bool cmp(node x, node y) { return x.w < y.w; }
void Add(long long x) {
  ++cnt[g[x].c];
  if (cnt[g[x].c] == 1) ++Col;
}
void Del(long long x) {
  --cnt[g[x].c];
  if (!cnt[g[x].c]) --Col;
}
signed main() {
  for (register long long i = (1); i <= (6); ++i) a[i] = gi();
  n = gi();
  for (register long long i = (1); i <= (n); ++i) b[i] = gi();
  sort(b + 1, b + n + 1);
  sort(a + 1, a + 7);
  for (register long long i = (1); i <= (n); ++i) {
    for (register long long j = (1); j <= (6); ++j)
      g[++top] = (node){i, b[i] - a[j]};
  }
  sort(g + 1, g + top + 1, cmp);
  long long l = 1;
  Col = 0;
  long long Ans = inf;
  for (register long long i = (1); i <= (top); ++i) {
    Add(i);
    while (l < i && (cnt[g[l].c] > 1) && (Col == n)) Del(l), ++l;
    if (Col == n) Ans = min(Ans, g[i].w - g[l].w);
  }
  cout << Ans << endl;
  return 0;
}
