#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const long double PI = 3.141592653589793238462643383279502884197;
long long fac[1] = {1}, inv[1] = {1};
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long mp(long long a, long long b) {
  long long ret = 1;
  while (b) {
    if (b & 1) ret = ret * a % MOD;
    a = a * a % MOD;
    b >>= 1;
  }
  return ret;
}
long long cmb(long long r, long long c) {
  return (c > r || c < 0) ? 0 : fac[r] * inv[c] % MOD * inv[r - c] % MOD;
}
int a[6];
int vec[100000];
int n;
int main() {
  for (int i = 0; i < 6; i++) scanf("%d", &a[i]);
  sort(a, a + 6);
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &vec[i]);
  sort(vec, vec + n);
  int ans = 2e9;
  if (n == 1) ans = 0;
  for (int i = 0; i < 6; i++) {
    int me = (vec[0] - a[i]);
    vector<pair<int, int> > v;
    v.reserve(n - 1);
    for (int j = 1; j < n; j++) {
      pair<int, int> rr = {-2e9, 2e9};
      for (int k = 0; k < 6; k++) {
        int now = (vec[j] - a[k]);
        if (now < me)
          rr.first = max(rr.first, now);
        else
          rr.second = min(rr.second, now);
      }
      if (rr.second > 1e9 + 7) rr.second = rr.first;
      if (rr.first < -1e9 - 7) rr.first = rr.second;
      v.push_back(rr);
    }
    sort((v).begin(), (v).end());
    int mav = -2e9;
    for (pair<int, int> j : v) {
      int lo = min(me, j.first);
      int hi = max(max(me, mav), v.back().first);
      ans = min(ans, hi - lo);
      mav = max(mav, j.second);
    }
  }
  printf("%d", ans);
}
