#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 1;
int a[6];
int n;
int b[MAXN];
int ptr[MAXN];
int f[MAXN][6];
int main() {
  for (int i = 0; i < 6; ++i) cin >> a[i];
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> b[i];
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < 6; ++j) {
      f[i][j] = b[i] - a[j];
    }
    sort(f[i], f[i] + 6);
  }
  fill(ptr, ptr + n, 0);
  priority_queue<pair<int, int>, vector<pair<int, int>>,
                 greater<pair<int, int>>>
      pq;
  int maxv = -1;
  for (int i = 0; i < n; ++i) {
    pq.push(make_pair(f[i][ptr[i]], i));
    maxv = max(maxv, f[i][ptr[i]]);
  }
  int minv = -1;
  int mini = -1;
  int diff = 1e9;
  pair<int, int> top;
  while (true) {
    top = pq.top();
    pq.pop();
    minv = top.first;
    diff = min(diff, maxv - minv);
    mini = top.second;
    if (ptr[mini] == 5) {
      break;
    }
    ++ptr[mini];
    pq.push(make_pair(f[mini][ptr[mini]], mini));
    maxv = max(maxv, f[mini][ptr[mini]]);
  }
  cout << diff << endl;
  return 0;
}
