#include <bits/stdc++.h>
using namespace std;
multiset<int> S;
vector<int> x, P[600000];
int A[6], B[100000], cnt[100000];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ((void)0);
  ((void)0);
  ((void)0);
  int N, ans = 0x7fffffff, asz;
  for (int i = 0; i < 6; i++) cin >> A[i];
  sort(A, A + 6);
  asz = unique(A, A + 6) - A;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> B[i];
    for (int j = 0; j < asz; j++) x.push_back(B[i] - A[j]);
  }
  sort(x.begin(), x.end());
  x.resize(unique(x.begin(), x.end()) - x.begin());
  for (int i = 0; i < N; i++) {
    int j = lower_bound(x.begin(), x.end(), B[i] - A[0]) - x.begin();
    P[j].push_back(i);
    S.insert(B[i] - A[0]);
  }
  ans = *S.rbegin() - *S.begin();
  for (int c = x.size(); --c >= 0;) {
    vector<pair<int, int>> temp;
    for (auto i : P[c])
      if (++cnt[i] < asz) temp.emplace_back(B[i] - A[cnt[i]], i);
    for (auto [v, i] : temp) {
      int j = lower_bound(x.begin(), x.end(), v) - x.begin();
      P[j].push_back(i);
      S.erase(S.find(x[c]));
      S.insert(v);
      ans = min(ans, *S.rbegin() - *S.begin());
    }
  }
  cout << ans << '\n';
  return 0;
}
