#include <bits/stdc++.h>
using namespace std;
int T, N, M, a[7], cnt[100001], ans = 0x3fffffff;
pair<int, int> b[6 * 100001];
int get() {
  int x = 0;
  char c = getchar();
  while (c < '0' || c > '9') c = getchar();
  while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
  return x;
}
int main() {
  for (int i = 1; i <= 6; i++) a[i] = get();
  N = get();
  for (int i = 1; i <= N; i++) {
    int x = get();
    for (int j = 1; j <= 6; j++) b[(i - 1) * 6 + j] = make_pair(x - a[j], i);
  }
  sort(b + 1, b + N * 6 + 1);
  int j = 0, tot = 0;
  for (int i = 1; i <= N * 6; i++) {
    while (j < N * 6 && tot < N)
      cnt[b[++j].second]++, cnt[b[j].second] == 1 ? tot++ : 0;
    if (tot == N) ans = min(ans, b[j].first - b[i].first);
    cnt[b[i].second]--;
    if (!cnt[b[i].second]) tot--;
  }
  cout << ans << endl;
  return 0;
}
