#include <bits/stdc++.h>
using namespace std;
const int MX = 1e6 + 5;
map<int, int> m, r;
vector<int> g[MX], t;
int n, id, mn, a[6], v[MX], c[MX], f[MX];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  for (int i = 0; i < 6; i++) cin >> a[i];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    for (int j = 0; j < 6; j++) t.push_back(v[i] - a[j]);
  }
  sort(t.begin(), t.end());
  id = 1;
  for (auto it : t) {
    if (!m.count(it)) {
      m[it] = id;
      r[id] = it;
      id++;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 6; j++) g[m[v[i] - a[j]]].push_back(i);
  }
  int i = 1, j = 0;
  f[0] = n;
  mn = INT_MAX;
  while (j < id) {
    while (!f[0] && i <= j) {
      mn = min(mn, r[j] - r[i]);
      for (auto it : g[i]) {
        f[c[it]]--;
        c[it]--;
        f[c[it]]++;
      }
      i++;
    }
    j++;
    if (j == id) break;
    for (auto it : g[j]) {
      f[c[it]]--;
      c[it]++;
      f[c[it]]++;
    }
  }
  cout << mn;
  return 0;
}
