#include <bits/stdc++.h>
using namespace std;
using pii = pair<long long, long long>;
using vi = vector<long long>;
using vvi = vector<vi>;
const signed INF_ = 1001001001;
const long long INF = 1001001001001001001LL;
const long long DX[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0},
                DY[9] = {-1, 0, 1, 0, -1, 1, 1, -1, 0};
template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  for (auto i = begin(v); i != end(v); i++)
    os << *i << (i == end(v) - 1 ? "" : " ");
  return os;
}
template <class T>
istream &operator>>(istream &is, vector<T> &v) {
  for (auto i = begin(v); i != end(v); i++) is >> *i;
  return is;
}
template <class T, class U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.first >> p.second;
  return is;
}
template <class T, class U>
bool chmax(T &a, const U &b) {
  return a < b ? a = b, 1 : 0;
}
template <class T, class U>
bool chmin(T &a, const U &b) {
  return a > b ? a = b, 1 : 0;
}
template <class T>
void psum(T &c) {
  partial_sum(begin(c), end(c), begin(c));
}
template <class T>
using heap = priority_queue<T, deque<T>, greater<T>>;
struct before_main_function {
  before_main_function() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(15) << fixed;
  }
} before_main_function;
signed main() {
  vi a(6);
  cin >> a;
  long long n;
  cin >> n;
  vi b(n);
  cin >> b;
  vector<pii> c;
  c.reserve(n * 6);
  for (long long i = 0, ilen = (long long)(n); i < ilen; ++i) {
    for (long long j = 0, jlen = (long long)(6); j < jlen; ++j) {
      c.emplace_back(b[i] - a[j], i);
    }
  }
  sort(begin(c), end(c));
  map<long long, long long> cnt;
  long long l = 0;
  long long ans = INF;
  for (long long r = 0, rlen = (long long)(((long long)c.size())); r < rlen;
       ++r) {
    cnt[c[r].second] += 1;
    while (((long long)cnt.size()) == n) {
      chmin(ans, c[r].first - c[l].first);
      if (cnt[c[l].second] == 1) {
        cnt.erase(c[l].second);
      } else {
        cnt[c[l].second] -= 1;
      }
      l += 1;
    }
  }
  cout << ans << endl;
}
