#include <bits/stdc++.h>
using namespace std;
int main(void) {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n, ans = 1E9, t = 0, maxV = 0;
  vector<int> A(6);
  for (int& a : A) cin >> a;
  cin >> n, sort(A.begin(), A.end());
  vector<int> B(n);
  vector<int> o(n);
  priority_queue<pair<int, int>> Q;
  for (int& a : B)
    cin >> a, Q.push(make_pair(A[5] - a, t)), maxV = max(maxV, a - A[5]),
                                              o[t++] = 5;
  while (true) {
    auto now = Q.top();
    ans = min(ans, maxV + now.first);
    if (o[now.second] == 0) break;
    int value = B[now.second] - A[--o[now.second]];
    Q.pop(), Q.push(make_pair(-value, now.second)), maxV = max(maxV, value);
  }
  cout << ans << '\n';
  return 0;
}
