#include <bits/stdc++.h>
using namespace std;
template <typename T>
T gcd(T a, T b) {
  return b == 0 ? a : gcd(b, a % b);
}
const int MAXN = 550;
int32_t main() {
  {
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
  };
  vector<int> a(6);
  for (int& i : a) {
    cin >> i;
  }
  int n;
  cin >> n;
  vector<int> b(n);
  for (int& i : b) {
    cin >> i;
  }
  vector<pair<int, int> > lads;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 6; j++) {
      lads.push_back({b[i] - a[j], i});
    }
  }
  sort((lads).begin(), (lads).end());
  int ans = INT_MAX;
  int cnt = 1;
  vector<int> cnt_(n, 0);
  cnt_[lads[0].second] = 1;
  int j = 0;
  for (int i = 1; i < ((int32_t)(lads).size()); i++) {
    cnt_[lads[i].second]++;
    if (cnt_[lads[i].second] == 1) {
      cnt++;
    }
    if (cnt != n) {
      continue;
    }
    while (cnt_[lads[j].second] != 1) {
      cnt_[lads[j].second]--;
      j++;
    }
    ans = min(ans, lads[i].first - lads[j].first);
  }
  cout << ans;
  return 0;
}
