#include <bits/stdc++.h>
using namespace std;
static vector<long long> a(6), b;
static long long n;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  for (int i = 0; i < 6; i++) {
    cin >> a[i];
  }
  cin >> n;
  vector<vector<long long> > g(n + 1);
  b.resize(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> b[i];
    for (int j = 0; j < 6; j++) g[i].push_back(b[i] - a[j]);
    sort(g[i].begin(), g[i].end());
  }
  set<pair<long long, long long> > s;
  for (int i = 1; i <= n; i++) s.insert({g[i][0], i});
  long long res = INT_MAX;
  vector<long long> pointer(n + 1, 0);
  while (true) {
    res = min(res, (*s.rbegin()).first - (*s.begin()).first);
    pair<long long, long long> curr = *s.begin();
    s.erase(s.begin());
    long long idx = curr.second;
    if (pointer[idx] + 1 == g[idx].size()) break;
    pointer[idx]++;
    s.insert({g[idx][pointer[idx]], idx});
  }
  cout << res << "\n";
  return 0;
}
