#include <bits/stdc++.h>
using namespace std;
template <typename T>
void setmax(T& x, T y) {
  x = max(x, y);
}
template <typename T>
void setmin(T& x, T y) {
  x = min(x, y);
}
template <typename T>
void print(const T& a, ostream& out) {
  for (auto i : a) out << i << ' ';
  out << endl;
}
const double PI = acos(-1.0);
const long long INF = 1e9 + 47;
const long long LINF = INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int n = 6;
const int M = 1 << 17;
int m;
int a[n], b[M];
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  for (int i = (0); i < (n); ++i) cin >> a[i];
  cin >> m;
  for (int i = (0); i < (m); ++i) cin >> b[i];
  sort(a, a + n);
  sort(b, b + m);
  int ans = INF;
  for (int DE = (0); DE < (n); ++DE)
    for (int DE2 = (0); DE2 < (m); ++DE2) {
      int mx = b[DE2] - a[DE];
      int mn = mx;
      int frst = 0;
      for (int i = (0); i < (n); ++i) {
        auto it = upper_bound(b, b + m, a[i] + mx) - b;
        if (frst < it) {
          setmin(mn, b[frst] - a[i]);
        }
        frst = it;
      }
      if (frst == m) {
        setmin(ans, mx - mn);
      }
    }
  assert(ans < INF);
  cout << ans << endl;
  cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
  return 0;
}
