#include <bits/stdc++.h>
using namespace std;
const int N = 1e5;
int a[6], n, b[N], ans, pointer[N];
vector<int> g[N];
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  for (int i = 0; i < 6; i++) cin >> a[i];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> b[i];
    for (int j = 0; j < 6; j++) g[i].push_back(b[i] - a[j]);
    sort(g[i].begin(), g[i].end());
  }
  set<pair<int, int>> fret;
  for (int i = 0; i < n; i++) fret.insert({g[i][0], i});
  ans = INT_MAX;
  while (1) {
    ans = min(ans, (*fret.rbegin()).first - (*fret.begin()).first);
    auto cur = (*fret.begin());
    fret.erase(fret.begin());
    int i = cur.second;
    pointer[i]++;
    if (pointer[i] == g[i].size()) break;
    fret.insert({g[i][pointer[i]], i});
  }
  cout << ans;
}
