#include <bits/stdc++.h>
using namespace std;
const int INF = 2e9;
const int SZ = 6;
int32_t main() {
  ios_base::sync_with_stdio(0);
  vector<int> b(SZ);
  for (int& e : b) cin >> e;
  int N;
  cin >> N;
  vector<pair<int, int>> arr(N * SZ);
  for (int i = 0, ix = 0; i < N; ++i) {
    int e1;
    cin >> e1;
    for (int& e2 : b) arr[ix++] = {e1 - e2, i};
  }
  sort(arr.begin(), arr.end());
  vector<vector<int>> index(N);
  for (int i = 0; i < arr.size(); ++i) index[arr[i].second].push_back(i);
  vector<int> cnt(N);
  int sz = 0;
  int finish = 0;
  int begin = 0;
  for (int i = 0; i < arr.size(); ++i) {
    int ix = arr[i].second;
    if (cnt[ix] == 0) {
      cnt[ix] = 1;
      ++sz;
    }
    if (sz == N) {
      finish = i;
      break;
    }
  }
  int mndiff = arr[finish].first - arr[begin].first;
  for (int i = 0; i < arr.size(); ++i) {
    begin++;
    int li = arr[i].second;
    auto it = upper_bound(index[li].begin(), index[li].end(), i);
    if (it == index[li].end()) break;
    if (*it > finish) finish = *it;
    mndiff = min(mndiff, arr[finish].first - arr[begin].first);
  }
  cout << mndiff;
}
