#include <bits/stdc++.h>
using namespace std;
template <class T>
ostream &operator<<(ostream &in, vector<T> &arr) {
  for (T &i : arr) {
    in << i << " ";
  }
  return in;
}
int main() {
  vector<int> a(6);
  for (int i = 0; i < 6; ++i) cin >> a[i];
  int n;
  cin >> n;
  vector<pair<int, int>> e;
  for (int i = 0; i < n; ++i) {
    int k;
    cin >> k;
    for (int j = 0; j < 6; ++j) {
      e.push_back({k - a[j], i});
    }
  }
  sort(e.begin(), e.end());
  vector<int> cnt(n, 0);
  int l = 0, r = 0;
  cnt[e[0].second] = 1;
  int cur = 1;
  int ans = 1e9;
  while (l < e.size()) {
    while (r < e.size() && cur < n) {
      r++;
      if (r < e.size()) {
        cnt[e[r].second]++;
        if (cnt[e[r].second] == 1) cur++;
      }
    }
    if (r >= e.size()) break;
    ans = min(ans, e[r].first - e[l].first);
    cnt[e[l].second]--;
    if (cnt[e[l].second] == 0) {
      cur--;
    }
    l++;
  }
  cout << ans;
  return 0;
}
