#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1;
const long long MOD = 1;
long long _gcd(long long a, long long b) {
  if (b == 0) return a;
  return _gcd(b, a % b);
}
long long gcd(long long a, long long b) {
  a = abs(a), b = abs(b);
  if (a < b) swap(a, b);
  return _gcd(a, b);
}
long long qpow(long long a, long long n) {
  long long rt = 1;
  while (n) {
    if (n & 1) rt = (rt * a) % MOD;
    a = a * a % MOD;
    n >>= 1;
  }
  return rt;
}
long long factor[MAXN];
long long inv[MAXN];
void cal_factor() {
  factor[0] = 1;
  for (int u = 1; u < MAXN; u++) {
    factor[u] = (factor[u - 1] * u) % MOD;
  }
}
void cal_factor_inv() {
  inv[0] = 1;
  inv[MAXN - 1] = qpow(factor[MAXN - 1], MOD - 2);
  for (int u = MAXN - 2; u >= 1; u--) {
    inv[u] = inv[u + 1] * (u + 1) % MOD;
  }
}
void init_factor() {
  cal_factor();
  cal_factor_inv();
}
long long C(long long n, long long k) {
  if (n < k) return 0;
  return factor[n] * qpow(factor[n - k], MOD - 2) % MOD *
         qpow(factor[k], MOD - 2) % MOD;
}
void solve() {
  int a[6];
  for (int u = 0; u < 6; u++) cin >> a[u];
  int n;
  cin >> n;
  vector<pair<int, int>> b;
  for (int u = 0; u < n; u++) {
    int tb;
    cin >> tb;
    for (int k = 0; k < 6; k++) {
      b.push_back({tb - a[k], u});
    }
  }
  sort(b.begin(), b.end());
  int ptr1 = 0, ptr2 = 0;
  vector<int> vis(n, 0);
  int cnt = 0;
  int ans = 2e9;
  for (; ptr2 < n * 6; ptr2++) {
    if (vis[b[ptr2].second] == 0) cnt++;
    vis[b[ptr2].second]++;
    while (cnt == n && ptr1 <= ptr2 && vis[b[ptr1].second]) {
      ans = min(ans, b[ptr2].first - b[ptr1].first);
      vis[b[ptr1].second]--;
      if (vis[b[ptr1].second] == 0) cnt--;
      ptr1++;
    }
  }
  cout << ans << "\n";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  solve();
}
