#include <bits/stdc++.h>
using namespace std;
inline long long rint() {
  long long x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * f;
}
inline long long gcd(long long a, long long b) {
  return (b) ? gcd(b, a % b) : a;
}
inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
inline long long pow(long long a, long long b, long long q) {
  long long rtn = 1;
  while (b) {
    if (b & 1) rtn = rtn * a % q;
    a = a * a % q;
    b >>= 1;
  }
  return rtn;
}
inline long long mysqrt(long long n) {
  long long x = sqrt(n);
  while (x * x < n) x++;
  while (x * x > n) x--;
  return x;
}
void solve() {
  vector<long long> a(6);
  for (int i = 0; i < 6; i++) a[i] = rint();
  sort((a).begin(), (a).end());
  int n = rint();
  vector<long long> b(n);
  for (int i = 0; i < n; i++) b[i] = rint();
  sort((b).begin(), (b).end());
  long long res = (b[n - 1] - a[0]) - (b[0] - a[5]);
  set<pair<long long, pair<long long, long long>>> s;
  for (int i = 0; i < n; i++) s.insert(make_pair(b[i] - a[5], make_pair(5, i)));
  while (1) {
    pair<long long, pair<long long, long long>> node = *s.begin();
    s.erase(node);
    if (node.second.first == 0) break;
    node.second.first--;
    node.first = b[node.second.second] - a[node.second.first];
    s.insert(node);
    res = min(res, (*s.rbegin()).first - (*s.begin()).first);
  }
  cout << res << "\n";
}
int main() {
  solve();
  return 0;
}
