#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using ld = long double;
using pii = pair<int, int>;
bool go(ll diff, vector<pair<ll, int>>& a, int n) {
  vi f(7 * n), ff(7 * n);
  int r = -1;
  ff[0] = n;
  for (int i = 0; i < a.size(); i++) {
    while (r + 1 < a.size() && a[i].first + diff >= a[r + 1].first) {
      int pos = a[r + 1].second;
      r++;
      ff[f[pos]]--;
      f[pos]++;
      ff[f[pos]]++;
    }
    if (ff[0] == 0) return true;
    int pos = a[i].second;
    ff[f[pos]]--;
    f[pos]--;
    ff[f[pos]]++;
  }
  return false;
}
void solve() {
  vi a(6);
  for (int& x : a) cin >> x;
  int n;
  cin >> n;
  vi b(n);
  for (int& x : b) cin >> x;
  vector<pair<ll, int>> evts;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < 6; j++) evts.emplace_back(b[i] - a[j], i);
  sort(begin(evts), end(evts));
  ll lo = 0, hi = 1e15;
  while (lo < hi) {
    ll mid = (lo + hi) / 2;
    if (go(mid, evts, n))
      hi = mid;
    else
      lo = mid + 1;
  }
  cout << hi << '\n';
}
int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin.exceptions(cin.failbit);
  solve();
  return 0;
}
