#include <bits/stdc++.h>
using namespace std;
void debug_out() { cout << "\n"; }
template <typename T1, typename... T2>
void debug_out(T1 A, T2... B) {
  cout << " " << A;
  debug_out(B...);
}
int test = 1;
struct Item {
  long long v;
  int i;
  bool operator<(Item t) const { return v < t.v; }
};
const int L = 100001;
int n;
long long A[6], x;
void solve() {
  for (int i = 0; i < 6; i++) cin >> A[i];
  cin >> n;
  vector<Item> N;
  for (int i = 0; i < n; i++) {
    cin >> x;
    for (int a = 0; a < 6; a++) {
      Item it = {x - A[a], i};
      N.push_back(it);
    }
  }
  sort(N.begin(), N.end());
  vector<int> C(n, 0);
  int c = 0;
  long long sol = LLONG_MAX;
  for (int i = 0, j = 0; i < N.size(); i++) {
    C[N[i].i]++;
    if (C[N[i].i] == 1) c++;
    while (C[N[j].i] > 1) {
      C[N[j].i]--;
      j++;
    }
    if (c == n) {
      sol = min(sol, N[i].v - N[j].v);
    }
  }
  cout << sol << endl;
}
int main(int argc, const char* argv[]) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  for (int testCount = 1; testCount <= test; testCount++) {
    solve();
  }
  return 0;
}
