#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 9;
const int INF = 1e9 + 7;
int a[7], b[maxn], id[maxn];
multiset<pair<int, int> > s;
int main() {
  int n;
  for (int i = 1; i <= 6; ++i) scanf("%d", &a[i]);
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &b[i]);
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= 6; ++j) s.insert(make_pair(b[i] - a[j], i));
  if (n == 1) {
    printf("0\n");
    return 0;
  }
  int ans = INF, cnt = 0;
  for (auto p : s) {
    if (!id[p.second]) ++cnt;
    id[p.second]++;
    while (cnt == n && id[(*s.begin()).second]) {
      pair<int, int> x = *s.begin();
      ans = min(ans, p.first - x.first);
      s.erase(s.begin(), ++s.begin());
      id[x.second]--;
      if (!id[x.second]) --cnt;
    }
  }
  printf("%d\n", ans);
  return 0;
}
