#include <bits/stdc++.h>
using namespace std;
int n, a[6], b, l, r, st[100000], su, ans = 2e9;
struct p {
  int x, n;
};
int cmp(p i, p j) { return i.n < j.n; }
vector<p> v;
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  for (int i = 0; i < 6; i++) cin >> a[i];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> b;
    for (int ii = 0; ii < 6; ii++) v.push_back(p{i, b - a[ii]});
  }
  sort(v.begin(), v.end(), cmp);
  while (r < v.size()) {
    while (r < v.size() && su < n) su += !st[v[r++].x]++;
    while (l < r && su == n) su -= st[v[l++].x]-- == 1;
    ans = min(ans, v[r - 1].n - v[l - 1].n);
  }
  cout << ans;
}
