#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  vector<int> a(6);
  for (int i = 0; i < 6; i++) cin >> a[i];
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  int n;
  cin >> n;
  vector<int> b(n);
  for (int i = 0; i < n; i++) cin >> b[i];
  sort(b.begin(), b.end());
  vector<vector<int> > r = vector<vector<int> >(6, vector<int>(n));
  for (int i = 0; i < n; i++)
    for (int j = 0; j < 6; j++) {
      r[j][i] = b[i] - a[j];
    }
  int bv = 15e8;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < 6; j++) {
      int st = 0;
      if (r[0][n - 1] > r[j][i]) continue;
      int mv = 15e8;
      for (int k = 5; k >= 0; k--) {
        if (st < n) mv = min(mv, r[k][st]);
        st = upper_bound(r[k].begin(), r[k].end(), r[j][i]) - r[k].begin();
      }
      bv = min(r[j][i] - mv, bv);
    }
  cout << bv << endl;
}
