#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void read(T &x) {
  x = 0;
  bool f = 0;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar()) f = ch == '-';
  for (; isdigit(ch); ch = getchar()) x = (x << 3) + (x << 1) + (ch ^ 48);
  x = f ? -x : x;
}
const int N = 1e5 + 5;
int num[11];
int book[N];
struct po {
  int num, id;
} a[6 * N];
const int INF = 2e9 + 5;
const bool cmp(const po &x, const po &y) {
  return (x.num < y.num) || (x.num == y.num && x.id < y.id);
}
int main() {
  int t = 6, n;
  for (int i = 1; i <= t; ++i) read(num[i]);
  read(n);
  int m = 0;
  for (int i = 1, tmp; i <= n; ++i) {
    read(tmp);
    for (int j = 1; j <= t; ++j) a[++m].num = tmp - num[j], a[m].id = i;
  }
  sort(a + 1, a + 1 + m, cmp);
  memset(book, 0, sizeof(book));
  int ans = INF, cnt = 0;
  for (int l = 1, r = 1; r <= m; ++r) {
    if (!book[a[r].id]) ++cnt;
    ++book[a[r].id];
    while (book[a[l].id] > 1) --book[a[l].id], ++l;
    if (cnt == n)
      ans = ((ans) < (a[r].num - a[l].num) ? (ans) : (a[r].num - a[l].num));
  }
  printf("%d\n", ans);
}
