#include <bits/stdc++.h>
using namespace std;
void banana() {
  vector<int> a(6);
  for (int i = 0; i < 6; i++) {
    cin >> a[i];
  }
  int n;
  cin >> n;
  vector<int> b(n);
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  sort(b.begin(), b.end());
  multiset<int> setik;
  set<pair<int, int> > dupa;
  vector<int> ind(n);
  int ans = 2e9;
  for (int i = 0; i < n; i++) {
    setik.insert(b[i] - a[ind[i]]);
    dupa.insert({b[i] - a[ind[i]], i});
  }
  ans = *setik.rbegin() - *setik.begin();
  while (true) {
    auto it = dupa.begin();
    auto p = *it;
    int val = p.first;
    int i = p.second;
    dupa.erase(it);
    setik.erase(setik.find(val));
    ind[i]++;
    if (ind[i] == 6) {
      break;
    }
    setik.insert(b[i] - a[ind[i]]);
    dupa.insert({b[i] - a[ind[i]], i});
    ans = min(ans, *setik.rbegin() - *setik.begin());
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cout.precision(12);
  cout << fixed;
  int t = 1;
  for (int tst = 0; tst < t; tst++) {
    banana();
  }
  return 0;
}
