#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:65536000")
using namespace std;
const double eps = 1e-8;
const double pi = 3.141592653589793238462643383279502884;
bool DEBUG = false;
void solve() {
  vector<long long> a(6);
  for (int i = 0; i < 6; ++i) cin >> a[i];
  sort(a.begin(), a.end());
  int n;
  cin >> n;
  vector<long long> b(n);
  for (int i = 0; i < n; ++i) cin >> b[i];
  set<pair<long long, long long>> notes;
  for (int i = 0; i < n; ++i) {
    notes.insert({b[i] - a[5], 5});
  }
  long long ans = notes.rbegin()->first - notes.begin()->first;
  while (true) {
    auto cur = notes.begin();
    long long value = cur->first;
    long long string = cur->second;
    if (string == 0) {
      cout << ans << '\n';
      return;
    }
    notes.erase(cur);
    value += a[string];
    string--;
    value -= a[string];
    notes.insert({value, string});
    ans = min(ans, notes.rbegin()->first - notes.begin()->first);
  }
}
int main() {
  cin.sync_with_stdio(0);
  solve();
  return 0;
}
