#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  int a[6];
  for (int i = 0; i < 6; i++) cin >> a[i];
  cin >> n;
  m = n * 6;
  vector<pair<int, int> > k(m);
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    for (int j = 0; j < 6; j++) k[i * 6 + j] = {x - a[j], i};
  }
  sort(k.begin(), k.end());
  int ans = 2e9;
  int R = m - 1;
  map<int, int> mp;
  for (int i = m - 1; i >= 0; i--) {
    mp[k[i].second]++;
    while (mp[k[R].second] > 1) {
      mp[k[R].second]--;
      R--;
    }
    if (mp.size() == n) {
      ans = min(ans, k[R].first - k[i].first);
    }
  }
  cout << ans;
}
