#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
using pil = pair<int, ll>;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int M = 1e9 + 7, N = 5e5 + 300, inf = INT_MAX;
int n, ans = inf, a[10], b[N], cnt, tc[N];
vector<pii> v;
multiset<int> s;
inline void add(int p) {
  tc[v[p].second]++;
  s.insert(v[p].first);
  if (tc[v[p].second] == 1) cnt++;
}
void solve() {
  for (int i = 1; i <= 6; i++) cin >> a[i];
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> b[i];
  v.push_back({-inf, -inf});
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= 6; j++) v.push_back({b[i] - a[j], i});
  }
  sort((v).begin(), (v).end());
  int j = 1;
  for (int i = 1; i <= 6 * n; i++) {
    while (j <= 6 * n && cnt < n) {
      add(j);
      j++;
    }
    if (cnt < n) break;
    auto it = s.begin();
    int x = *it;
    it = s.end();
    it--;
    int y = *it;
    ans = min(ans, y - x);
    tc[v[i].second]--;
    if (!tc[v[i].second]) cnt--;
    s.erase(s.lower_bound(v[i].first));
  }
  cout << ans << "\n";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int T = 1;
  while (T--) {
    solve();
  }
}
