#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int a[7], n, b[N], qqq[N][7], forever = 0;
int ans = 2e9;
struct d {
  int fro, af;
  bool operator<(const d x) const {
    return b[fro] - a[af] < b[x.fro] - a[x.af];
  }
} qwq, ovo;
priority_queue<d> qaq;
bool cmp(int x, int y) { return x > y; }
int main() {
  for (int i = 1; i <= 6; i++) scanf("%d", &a[i]);
  sort(a + 1, a + 6 + 1, cmp);
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &b[i]);
  int maxn = 0, minn = 2e9;
  for (int o = 1; o <= n; o++) {
    qwq.af = 6;
    qwq.fro = o;
    qaq.push(qwq);
    minn = min(minn, b[o] - a[qwq.af]);
  }
  while (!qaq.empty()) {
    qwq = qaq.top();
    qaq.pop();
    maxn = b[qwq.fro] - a[qwq.af];
    ans = min(ans, max(forever, maxn) - minn);
    if (qwq.af > 1) {
      ovo.af = qwq.af - 1;
      ovo.fro = qwq.fro;
      minn = min(minn, b[ovo.fro] - a[ovo.af]);
      qaq.push(ovo);
    } else {
      forever = max(forever, b[qwq.fro] - a[qwq.af]);
    }
  }
  printf("%d\n", ans);
}
