#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = -1;
  for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
  return x * f;
}
const int MAXN = 150010;
const int INF = 2147483600;
int a[99], b[MAXN + 1];
int N;
inline bool check(int l, int r) {
  for (int i = 1; i < 6; i++) {
    int lx = upper_bound(b + 1, b + N + 1, a[i] + r) - b;
    int rx = lower_bound(b + 1, b + N + 1, a[i + 1] + l) - b - 1;
    if (lx <= rx) return 0;
  }
  return 1;
}
inline int Query(int x) {
  int l = max(b[N] - a[6], x), r = 1000000000, ans;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (check(x, mid))
      ans = mid, r = mid - 1;
    else
      l = mid + 1;
  }
  return ans - x;
}
int main() {
  for (int i = 1; i <= 6; i++) a[i] = read();
  sort(a + 1, a + 6 + 1);
  N = read();
  for (int i = 1; i <= N; i++) b[i] = read();
  sort(b + 1, b + N + 1);
  int l = b[1] - a[1];
  int ans = INF;
  for (int i = 1; i <= 6; i++) {
    for (int j = 1; j <= N; j++) {
      if (b[j] - a[i] <= l) {
        ans = min(ans, Query(b[j] - a[i]));
      }
    }
  }
  printf("%d\n", max(ans, 0));
  return 0;
}
