#include <bits/stdc++.h>
using namespace std;
signed main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  long long k = 6;
  vector<long long> A(k);
  for (long long i = 0; i < k; i++) cin >> A[i];
  sort((A).begin(), (A).end());
  reverse((A).begin(), (A).end());
  long long n;
  cin >> n;
  vector<long long> B(n);
  for (long long i = 0; i < n; i++) cin >> B[i];
  set<pair<long long, long long>> C;
  for (long long i = 0; i < n; i++) {
    C.insert({B[i] - A[0], i});
  }
  vector<long long> D(n, 0);
  long long ans = 1e18 + 9;
  while (true) {
    ans = min(ans, ((*C.rbegin()).first - (*C.begin()).first));
    long long pos = (*C.begin()).second;
    D[pos]++;
    C.erase(C.begin());
    if (D[pos] == k) break;
    C.insert({B[pos] - A[D[pos]], pos});
  }
  cout << ans;
}
