#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 1;
signed main() {
  vector<long long> a(6);
  for (long long i = 0; i < 6; ++i) cin >> a[i];
  long long n;
  cin >> n;
  vector<pair<long long, long long>> arr;
  for (long long i = 0; i < n; ++i) {
    long long b;
    cin >> b;
    for (long long j = 0; j < 6; ++j) arr.push_back({b - a[j], i});
  }
  vector<long long> cnt(n);
  sort(arr.begin(), arr.end());
  long long i = 0, j = 0, best = INF, s = 0;
  while (i < arr.size()) {
    while (s < n && j < arr.size()) {
      if (++cnt[arr[j].second] == 1) ++s;
      ++j;
    }
    if (s == n) best = min(best, arr[j - 1].first - arr[i].first);
    if (--cnt[arr[i].second] == 0) --s;
    ++i;
  }
  cout << best;
}
