#include <bits/stdc++.h>
using namespace std;
const long long MOD = (long long)998244353;
const int SIZE = 2e5 + 5;
const long long INF = 1LL << 60;
const double eps = 1e-4;
const double PI = 3.1415926535897932;
long long a[6], b[100009];
int main() {
  for (int i = 0; i < (6); ++i) scanf("%lld", &a[i]);
  int(n);
  scanf("%d", &n);
  for (int i = 0; i < (n); ++i) scanf("%lld", &b[i]);
  unordered_map<int, int> good;
  vector<pair<int, int> > v;
  for (int i = 0; i < (n); ++i) {
    for (int j = 0; j < (6); ++j) {
      v.push_back({b[i] - a[j], i});
    }
  }
  sort((v).begin(), (v).end());
  int ans = 2e9;
  int l = 0;
  for (int r = 0; r < (6 * n); ++r) {
    pair<int, int> rv = v[r];
    good[rv.second]++;
    pair<int, int> lv = v[l];
    while (good.count(lv.second) && good[lv.second] > 1) {
      good[lv.second]--;
      l++;
      lv = v[l];
    }
    if (((int)(good).size()) == n) ans = min(ans, v[r].first - v[l].first);
  }
  printf("%d", ans);
}
