#include <bits/stdc++.h>
using namespace std;
using ii = pair<int, int>;
const int mxn = 100010, INF = 2147483647;
vector<int> xlist;
int b[6], a[mxn], N;
int cnt[mxn * 6], tot;
vector<ii> xi;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  for (int i = 0; i < 6; i++) cin >> b[i];
  cin >> N;
  for (int i = 0; i < N; i++) cin >> a[i];
  sort(a, a + N);
  for (int i = 0; i < N; i++)
    for (int j = 0; j < 6; j++) xi.push_back({a[i] - b[j], i});
  sort((xi).begin(), (xi).end());
  int sz = xi.size(), ans = INF;
  for (int l = 0, r = 0; l < sz; l++) {
    while (r < sz && tot != N) {
      if (cnt[xi[r].second]++ == 0) tot++;
      r++;
    }
    if (tot == N) ans = min(ans, xi[r - 1].first - xi[l].first);
    if (--cnt[xi[l].second] == 0) tot--;
  }
  cout << ans;
  return 0;
}
