#include <bits/stdc++.h>
using namespace std;
bool DEB = false;
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("fast-math")
#pragma GCC optimize "-O3"
void MP() {
  ios::sync_with_stdio(false);
  cin.tie(0);
}
const long long INF = (long long)1e9 + 9;
const long long MAX = (long long)1e5 + 10;
void solve() {
  long long a[6];
  for (long long i = 0; i < 6; ++i) cin >> a[i];
  long long n;
  cin >> n;
  long long b[n];
  for (long long i = 0; i < n; ++i) cin >> b[i];
  vector<pair<long long, long long>> line;
  for (long long i = 0; i < 6; ++i) {
    for (long long j = 0; j < n; ++j) {
      line.push_back({b[j] - a[i], j});
    }
  }
  sort(line.begin(), line.end());
  long long r = 0;
  long long isOpen[n];
  fill(isOpen, isOpen + n, 0);
  long long opened = 0;
  long long ans = INF;
  if (!isOpen[line[0].second]) {
    ++opened;
  }
  ++isOpen[line[0].second];
  if (DEB)
    cout << "sz(line)"
         << " : " << (long long)line.size() << endl;
  ;
  if (DEB)
    cout << "n"
         << " : " << n << endl;
  ;
  for (long long l = 0; l < (long long)line.size(); ++l) {
    auto x = line[l];
    while (r + 1 < (long long)line.size() && opened < n) {
      if (DEB)
        cout << "r"
             << " : " << r << endl;
      ;
      if (DEB)
        cout << "opened"
             << " : " << opened << endl;
      ;
      ++r;
      if (!isOpen[line[r].second]) {
        ++opened;
      }
      ++isOpen[line[r].second];
    }
    if (opened != n) break;
    if (DEB)
      cout << "l"
           << " : " << l << endl;
    ;
    if (DEB)
      cout << "r"
           << " : " << r << endl;
    ;
    if (DEB)
      cout << "opened"
           << " : " << opened << endl;
    ;
    assert(r >= l);
    ans = min(ans, line[r].first - line[l].first);
    if (DEB)
      cout << "isOpen[x.se]"
           << " : " << isOpen[x.second] << endl;
    ;
    if (isOpen[x.second] == 1) --opened;
    --isOpen[x.second];
  }
  cout << ans;
}
signed main() {
  MP();
  long long T = 1;
  while (T--) solve();
  return 0;
}
