#include <bits/stdc++.h>
using namespace std;
template <typename T>
ostream& operator<<(ostream& out, const vector<T>& vec) {
  out << "[";
  for (int x : vec) out << x << ", ";
  out << "]";
  return out;
}
int a[6];
int n;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  for (int i = 0; i < 6; i++) cin >> a[i];
  cin >> n;
  vector<pair<int, int>> x;
  for (int i = 0; i < n; i++) {
    int b;
    cin >> b;
    for (int j = 0; j < 6; j++) {
      x.emplace_back(b - a[j], i);
    }
  }
  sort(x.begin(), x.end());
  int ans = x[x.size() - 1].first - x[0].first;
  vector<int> cnt(n, 0);
  int cplt = 0;
  int r = 0;
  for (int l = 0; l < (int)x.size(); l++) {
    while (cplt < n) {
      if (r >= (int)x.size()) break;
      if (cnt[x[r].second] == 0) cplt++;
      cnt[x[r].second]++;
      r++;
    }
    if (cplt == n) {
      ans = min(ans, x[r - 1].first - x[l].first);
    }
    if (cnt[x[l].second] == 1) cplt--;
    cnt[x[l].second]--;
  }
  cout << ans << '\n';
  return 0;
}
