#include <bits/stdc++.h>
using pii = std::pair<long long, long long>;
using namespace std;
const long long maxn = 1e5 + 5, maxfret = 7;
long long n, a[maxfret], b[maxn];
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  for (long long i = 0; i < 6; i++) cin >> a[i];
  sort(a, a + 6);
  cin >> n;
  for (long long i = 0; i < n; i++) cin >> b[i];
  sort(b, b + n);
  multiset<pair<long long, pii>> vals;
  for (long long i = 0; i < n; i++) vals.insert({b[i] - a[5], {5, i}});
  long long ans = vals.rbegin()->first - vals.begin()->first;
  while (vals.begin()->second.first > 0) {
    long long idx = vals.begin()->second.second;
    long long red = vals.begin()->second.first - 1;
    vals.erase(vals.begin());
    vals.insert({b[idx] - a[red], {red, idx}});
    ans = min(ans, vals.rbegin()->first - vals.begin()->first);
  }
  cout << ans << "\n";
  return 0;
}
