#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18, MOD = 1e9 + 7, MAXN = 18, MAXM = 1e5 + 1;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long qw = 1;
  while (qw--) {
    vector<long long> f(6);
    for (long long i = 0; i < 6; i++) cin >> f[i];
    long long n, a, ans_mx = -INF, ans_mn = INF;
    cin >> n;
    vector<pair<long long, long long>> mx;
    for (long long i = 0; i < n; i++) {
      cin >> a;
      for (long long j = 0; j < 6; j++) {
        mx.push_back({a - f[j], i});
      }
    }
    sort((mx).begin(), (mx).end());
    long long m = mx.size();
    long long res = INF, p = 0, r = -1;
    vector<long long> ans(n);
    for (long long i = 0; i < m; i++) {
      ans[mx[i].second]++;
      if (ans[mx[i].second] == 1) p++;
      if (p < n) continue;
      while (ans[mx[r + 1].second] > 1) {
        ans[mx[r + 1].second]--;
        r++;
      }
      res = min(res, mx[i].first - mx[r + 1].first);
    }
    cout << res;
  }
}
