#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long a[6];
  for (long long i = 0; i < 6; i++) cin >> a[i];
  sort(a, a + 6);
  long long n;
  cin >> n;
  long long b[n];
  for (long long i = 0; i < n; i++) cin >> b[i];
  if (n == 1) {
    cout << 0 << '\n';
    return;
  }
  sort(b, b + n);
  vector<long long> v[n];
  vector<long long> all;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < 6; j++) {
      v[i].push_back(b[i] - a[j]);
      all.push_back(b[i] - a[j]);
    }
    sort(v[i].begin(), v[i].end());
  }
  sort(all.begin(), all.end());
  multiset<pair<long long, long long> > cur;
  for (long long i = 0; i < n; i++) {
    cur.insert({v[i].back(), i});
    v[i].pop_back();
  }
  long long ans = 1e18;
  while (all.size()) {
    long long now = all.back();
    all.pop_back();
    bool gen = 0;
    while (true) {
      auto low = cur.upper_bound(make_pair(now, 1e9));
      if (low == cur.end() || low->first <= now) break;
      if (low->first > now) {
        long long idx = low->second;
        cur.erase(low);
        while (true) {
          if (v[idx].size() == 0) {
            gen = 1;
            break;
          }
          if (v[idx].back() <= now) {
            cur.insert({v[idx].back(), idx});
            v[idx].pop_back();
            break;
          }
          v[idx].pop_back();
        }
      }
      if (gen) break;
    }
    if (gen) break;
    long long mn = cur.begin()->first;
    ans = min(ans, abs(mn - now));
  }
  cout << ans;
}
int main() {
  long long t;
  t = 1;
  while (t--) {
    solve();
  }
}
