#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <class T>
inline bool setmin(T &a, T b) {
  if (a > b) return a = b, 1;
  return 0;
}
template <class T>
inline bool setmax(T &a, T b) {
  if (a < b) return a = b, 1;
  return 0;
}
template <class T>
inline T fast(T a, T b, T mod) {
  long long res = 1;
  while (b) {
    if (b & 1) res = (res * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return res;
}
template <class T>
istream &operator>>(istream &os, vector<T> &container) {
  for (auto &u : container) os >> u;
  return os;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &container) {
  for (auto &u : container) os << u << " ";
  return os;
}
template <class T>
inline T gcd(T a, T b) {
  while (b) swap(a %= b, b);
  return abs(a);
}
const long long INF = 1e9 + 7;
const long long mod = 998244353;
const long long BIG_INF = 1e18 + 7;
const long long N = 1e6 + 7;
const long long T = 1 << 20;
const long double inf = 1e18;
const long double eps = 1e-14;
long long n, m, k, poz;
void solve() {
  vector<int> a(6);
  cin >> a;
  cin >> n;
  vector<int> tab(n);
  cin >> tab;
  sort((tab).begin(), (tab).end());
  vector<vector<int> > siema(n);
  int mini = 0;
  vector<vector<int> > events;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 6; j++) siema[i].push_back(tab[i] - a[j]);
    sort((siema[i]).begin(), (siema[i]).end());
    for (int j = 0; j < 6; j++) events.push_back({siema[i][j], i, j});
    mini = max(mini, siema[i][0]);
  }
  sort((events).begin(), (events).end());
  int ans = INF * 2;
  for (auto &u : events) {
    ans = min(ans, mini - u[0]);
    if (u[2] == 5) break;
    mini = max(mini, siema[u[1]][u[2] + 1]);
  }
  cout << ans << '\n';
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t = 1;
  while (t--) solve();
}
