#include <bits/stdc++.h>
using namespace std;
const int maxl = 3e5 + 10;
int n, m, cnt, tot, cas, ans;
int a[maxl], b[maxl], num[maxl];
struct node {
  int val, id;
} c[maxl * 6];
bool vis[maxl];
char s[maxl];
inline bool cmp(const node &a, const node &b) { return a.val < b.val; }
inline void prework() {
  for (int i = 1; i <= 6; i++) scanf("%d", &a[i]);
  sort(a + 1, a + 1 + 6);
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &b[i]);
  sort(b + 1, b + 1 + n);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= 6; j++) c[++tot] = node{b[i] - a[j], i};
  sort(c + 1, c + 1 + tot, cmp);
}
inline void mainwork() {
  ans = b[n] - b[1];
  int r = 0, now = 0;
  for (int i = 1; i <= tot; i++) {
    while (now < n && r < tot) now += !num[c[++r].id]++;
    if (now < n) break;
    ans = min(ans, c[r].val - c[i].val);
    now -= !--num[c[i].id];
  }
}
inline void print() { printf("%d\n", ans); }
int main() {
  int t = 1;
  for (cas = 1; cas <= t; cas++) {
    prework();
    mainwork();
    print();
  }
  return 0;
}
