#include <bits/stdc++.h>
using namespace std;
long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') f = -1;
  for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
  return x * f;
}
int a[10], b[100001], mn = 1000000000, mx = 0;
int c[110100][10], num[101010];
struct Data {
  int num, x;
  bool operator<(const Data &tmp) const { return num < tmp.num; }
} d[600001];
int cnt;
int main() {
  for (int i = 1; i <= 6; i++) {
    a[i] = read();
  }
  int n = read();
  for (int i = 1; i <= n; i++) {
    b[i] = read();
    for (int j = 1; j <= 6; j++) {
      d[++cnt].num = b[i] - a[j];
      d[cnt].x = i;
    }
  }
  sort(d + 1, d + cnt + 1);
  int mn = 2147483647, r = 1, tot = 0;
  for (int i = 1; i <= cnt; i++) {
    while (tot < n && r <= cnt) {
      if (!num[d[r].x]) {
        tot++;
      }
      num[d[r].x]++;
      r++;
    }
    if (tot == n) mn = min(mn, d[r - 1].num - d[i].num);
    num[d[i].x]--;
    if (!num[d[i].x]) tot--;
  }
  cout << mn;
}
