#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int ret = 0;
  char ch = getchar();
  while (!isdigit(ch)) ch = getchar();
  while (isdigit(ch)) ret = (ret << 1) + (ret << 3) + ch - '0', ch = getchar();
  return ret;
}
const int N = 1e5 + 5;
pair<int, int> num[N * 6];
int n, m, ans;
int a[8], b[N], cnt[N];
int main() {
  register int i, j;
  for (i = 1; i <= 6; i++) a[i] = read();
  for (n = read(), i = 1; i <= n; i++)
    for (b[i] = read(), j = 1; j <= 6; j++)
      num[++m] = make_pair(b[i] - a[j], i);
  sort(num + 1, num + m + 1);
  int tot = 0;
  for (i = j = 1; j <= m; j++) {
    if (!cnt[num[j].second]) tot++;
    cnt[num[j].second]++;
    if (tot == n) break;
  }
  i = 1;
  ans = num[j].first - num[i].first;
  while (j <= m) {
    cnt[num[i].second]--;
    while (j <= m && !cnt[num[i].second]) j++, cnt[num[j].second]++;
    i++;
    if (j <= m) ans = min(ans, num[j].first - num[i].first);
  }
  return printf("%d\n", ans), 0;
}
