#include <bits/stdc++.h>
using namespace std;
const long long N = 1000006, INF = 1e18, MOD = 1e9 + 7;
int n, m, r, t, a[N], b[N], c[N][7], e, o, u, k, x, y, ans, Ans[N], mx;
vector<long long> v;
set<pair<int, pair<int, int> > > s;
set<pair<int, pair<int, int> > >::iterator it, It;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0);
  cin >> a[1] >> a[2] >> a[3] >> a[4] >> a[5] >> a[6] >> n;
  sort(a + 1, a + 7);
  for (int i = 1; i <= 3; i++) swap(a[i], a[7 - i]);
  for (int i = 1; i <= n; i++) {
    cin >> b[i];
    for (int j = 1; j <= 6; j++)
      c[i][j] = b[i] - a[j], v.push_back(b[i] - a[j]);
    s.insert({c[i][1], {1, i}});
  }
  it = s.begin();
  It = s.end();
  It--;
  ans = (*It).first - (*it).first;
  sort(v.begin(), v.end());
  for (int i = 0; i < v.size(); i++) {
    x = v[i];
    while (s.size() > 0 && (*s.begin()).first < x) {
      it = s.begin();
      if ((*it).second.first == 6) {
        i = v.size() + 1;
        break;
      }
      s.insert({c[(*it).second.second][(*it).second.first + 1],
                {(*it).second.first + 1, (*it).second.second}});
      s.erase(it);
    }
    it = s.begin();
    It = s.end();
    It--;
    ans = min(ans, (*It).first - (*it).first);
  }
  cout << ans << endl;
}
