#include <bits/stdc++.h>
using namespace std;
mt19937 rng(
    (unsigned int)chrono::steady_clock::now().time_since_epoch().count());
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long int a[6];
  for (long long int i = 0; i < 6; i++) {
    cin >> a[i];
  }
  long long int n;
  cin >> n;
  vector<long long int> what(n);
  vector<pair<long long int, long long int>> p;
  for (long long int i = 0; i < n; i++) {
    cin >> what[i];
    for (long long int j = 0; j < 6; j++) {
      p.push_back({what[i] - a[j], i});
    }
  }
  vector<long long int> bc(n);
  sort(p.begin(), p.end());
  long long int left = 0, right = 0;
  long long int kya = 0;
  while (kya < n && right < p.size()) {
    if (bc[p[right].second] == 0) {
      bc[p[right].second]++;
      kya++;
      right++;
    } else {
      bc[p[right].second]++;
      right++;
    }
  }
  long long int ans = p[right - 1].first - p[left].first;
  while (right < p.size()) {
    if (bc[p[left].second] == 1) {
      bc[p[left].second]--;
      kya--;
      left++;
    } else {
      bc[p[left].second]--;
      left++;
    }
    while (kya < n && right < p.size()) {
      if (bc[p[right].second] == 0) {
        bc[p[right].second]++;
        kya++;
        right++;
      } else {
        bc[p[right].second]++;
        right++;
      }
    }
    if (kya == n) {
      ans = min(ans, p[right - 1].first - p[left].first);
    }
  }
  cout << ans << "\n";
}
