#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  vector<int> a(6);
  for (auto &i : a) cin >> i;
  int n;
  cin >> n;
  vector<int> b(n);
  for (auto &i : b) cin >> i;
  sort(b.begin(), b.end());
  sort(a.begin(), a.end());
  set<pair<int, int> > jp;
  vector<int> cnt(n);
  for (int x = 0; x < n; x++) jp.insert({b[x] - a[cnt[x]], x});
  int ans = INT_MAX;
  while (true) {
    auto [val, x] = *jp.rbegin();
    if (cnt[x]++ > 5) break;
    jp.erase(*jp.rbegin());
    jp.insert({b[x] - a[cnt[x]], x});
    ans = min(ans, jp.rbegin()->first - jp.begin()->first);
  }
  cout << ans << endl;
  return 0;
}
