#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 123, bs = 500;
const long long INF = 1e15;
int n, was[N];
long long a[10], b[N], old[N];
vector<pair<long long, int> > g;
set<pair<long long, int> > st;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  for (int i = 1; i <= 6; i++) cin >> a[i];
  cin >> n;
  int gz = n;
  for (int i = 1; i <= n; i++) {
    cin >> b[i];
    for (int j = 1; j <= 6; j++) {
      g.push_back(make_pair(b[i] - a[j], i));
    }
  }
  sort(g.begin(), g.end());
  long long res = INF;
  for (pair<long long, int> v : g) {
    if (was[v.second] == 0) {
      was[v.second] = 1, gz -= 1;
      st.insert(make_pair(v.first, v.second));
      old[v.second] = v.first;
    } else {
      st.erase(make_pair(old[v.second], v.second));
      old[v.second] = v.first;
      st.insert(make_pair(v.first, v.second));
    }
    if (gz == 0) {
      pair<long long, int> rx = *st.begin(), ry = *st.rbegin();
      res = min(res, ry.first - rx.first);
    }
  }
  cout << res;
}
