#include <bits/stdc++.h>
using namespace std;
long long seed = time(0);
mt19937 gen(seed);
bool IS_ONE_TEST = 1;
void solve() {
  mt19937 local_gen(152);
  vector<long long> a(6);
  for (int i = 0; i < 6; ++i) cin >> a[i];
  long long n;
  cin >> n;
  vector<long long> b(n);
  for (int j = 0; j < n; ++j) cin >> b[j];
  sort((a).begin(), (a).end());
  sort((b).begin(), (b).end());
  long long ans = 3e9;
  vector<pair<long long, long long>> c;
  for (int i = 0; i < 6; ++i) {
    for (int j = 0; j < n; ++j) {
      c.emplace_back(b[j] - a[i], j);
    }
  }
  sort((c).begin(), (c).end());
  int l = 0;
  vector<int> g(n + 1);
  int tot = 0;
  for (int i = 0; i < 6 * n; ++i) {
    ++g[c[i].second];
    if (g[c[i].second] == 1) ++tot;
    while (l < 6 * n && g[c[l].second] > 1) {
      --g[c[l].second];
      ++l;
    }
    if (tot == n) ans = min(ans, c[i].first - c[l].first);
  }
  cout << ans << endl;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  srand(time(0));
  cout << fixed << setprecision(15);
  int T = 1;
  if (!IS_ONE_TEST) cin >> T;
  while (T-- > 0) solve();
}
