#include <bits/stdc++.h>
using namespace std;
template <class T>
T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const double EPS = 1e-9;
const double PI = acos(-1.);
const long long LL_INF = 1e17 + 16;
const int INF = 1e9 + 10;
const long long MOD = 1e9 + 7;
const int MAXN = 6e5 + 5;
int a[MAXN];
pair<int, int> pp[MAXN];
int cnt[MAXN];
void solve() {
  for (int i = (0); i < (int)(6); i++) {
    scanf("%d", &a[i]);
  }
  int n;
  scanf("%d", &n);
  for (int i = (0); i < (int)(n); i++) {
    int b;
    scanf("%d", &b);
    for (int j = (0); j < (int)(6); j++) {
      pp[6 * i + j] = {b - a[j], i};
    }
  }
  sort(pp, pp + 6 * n);
  int l = 0, r = 0;
  int bad = n;
  int ans = pp[6 * n - 1].first - pp[0].first;
  for (; l < 6 * n;) {
    for (; r < 6 * n && bad > 0;) {
      int r1 = r;
      for (r1 = r; r1 < 6 * n && pp[r1].first == pp[r].first; r1++) {
        int ind = pp[r1].second;
        if (!cnt[ind]) {
          bad--;
        }
        cnt[ind]++;
      }
      r = r1;
    }
    if (bad == 0) {
      ans = min(ans, pp[r - 1].first - pp[l].first);
    } else {
      break;
    }
    int l1 = l;
    for (l1 = l; l1 < 6 * n && pp[l1].first == pp[l].first; l1++) {
      int ind = pp[l1].second;
      cnt[ind]--;
      if (cnt[ind] == 0) {
        bad++;
      }
    }
    l = l1;
  }
  printf("%d\n", ans);
}
int main() {
  int t = 1;
  while (t--) {
    solve();
  }
}
