#include <bits/stdc++.h>
using namespace std;
long long poww(long long a, long long b, long long md) {
  return (!b ? 1
             : (b & 1 ? a * poww(a * a % md, b / 2, md) % md
                      : poww(a * a % md, b / 2, md) % md));
}
const long long MAXN = 1e6 + 10;
const long long INF = 8e18;
const long long MOD = 1e9 + 7;
long long A[6], n, B[MAXN];
vector<long long> S[MAXN];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  for (int i = 0; i < 6; i++) cin >> A[i];
  cin >> n;
  vector<pair<long long, long long> > v;
  long long ans = INF, mx = 0;
  for (int i = 0; i < n; i++) {
    long long x;
    cin >> x;
    for (int j = 0; j < 6; j++)
      S[i].push_back(x - A[j]), v.push_back({x - A[j], i});
    sort((S[i]).begin(), (S[i]).end());
    mx = max(mx, S[i].front());
  }
  sort((v).begin(), (v).end());
  reverse((v).begin(), (v).end());
  while (!v.empty()) {
    pair<long long, long long> e = v.back();
    v.pop_back();
    ans = min(ans, mx - e.first);
    S[e.second].erase(S[e.second].begin());
    if (S[e.second].empty()) break;
    mx = max(mx, S[e.second].front());
  }
  cout << ans << '\n';
  return 0;
}
