#include <bits/stdc++.h>
using namespace std;
long long read() {
  long long w = 0, f = 1;
  char c = ' ';
  while (c < '0' || c > '9') c = getchar(), f = c == '-' ? -1 : f;
  while (c >= '0' && c <= '9') w = w * 10 + c - 48, c = getchar();
  return w * f;
}
struct node {
  long long x, y;
} t[2000005];
bool cmp(node x, node y) { return x.x < y.x; }
long long a[10], n, b[2000005], cnt, p[2000005];
signed main() {
  for (long long i = 1; i <= 6; i++) a[i] = read();
  n = read();
  for (long long i = 1; i <= n; i++) b[i] = read();
  for (long long i = 1; i <= n; i++)
    for (long long j = 1; j <= 6; j++) t[++cnt].x = b[i] - a[j], t[cnt].y = i;
  sort(t + 1, t + cnt + 1, cmp);
  long long it1 = 1, it2 = 1, sum = 0, ans = 2e9;
  for (; it2 <= cnt; it2++) {
    if (!p[t[it2].y]) sum++;
    p[t[it2].y]++;
    while (p[t[it1].y] > 1) p[t[it1].y]--, it1++;
    if (sum == n) ans = min(ans, t[it2].x - t[it1].x);
  }
  printf("%lld\n", ans);
  return 0;
}
