#include <bits/stdc++.h>
using namespace std;
const int INF = 2147483647;
const long long LONGINF = 9223372036854775807;
const long long MOD = 1e9 + 7;
int a[6];
vector<pair<int, int>> lads;
multiset<int> nots;
void solve() {
  for (int i = 0; i < 6; ++i) cin >> a[i];
  int n;
  cin >> n;
  while (n--) {
    int b;
    cin >> b;
    for (int i = 0; i < 6; ++i) lads.push_back({b - a[i], n});
  }
  sort((lads).begin(), (lads).end());
  int l = 0, r = 0, minRes = INF, amount = 0;
  while (r < lads.size()) {
    if (nots.count(lads[r].second) == 0) ++amount;
    nots.insert(lads[r].second);
    while (nots.count(lads[l].second) >= 2) {
      nots.erase(nots.find(lads[l].second));
      ++l;
    }
    if (amount == lads.size() / 6)
      minRes = min(minRes, lads[r].first - lads[l].first);
    ++r;
  }
  cout << minRes << '\n';
}
signed main() {
  cin.tie(0);
  cout.tie(0);
  std::ios_base::sync_with_stdio(0);
  bool mult = false;
  if (mult) {
    int t;
    cin >> t;
    while (t--) solve();
  } else
    solve();
  return 0;
}
