#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimization("unroll-loops")
const int N = 1e5 + 5;
const long long int mod = 1e9 + 7;
const long long int Mod = 998244353;
const long double Pi = acos(-1);
const long long int Inf = 4e18;
int dx[9] = {0, 1, -1, 0, 0, 1, 1, -1, -1};
int dy[9] = {0, 0, 0, 1, -1, 1, -1, 1, -1};
using namespace std;
void TestCase() {
  int a[7], b[N], n, ans = INT_MAX, lst = 0;
  for (int i = 1; i <= 6; i++) cin >> a[i];
  cin >> n;
  vector<pair<int, int> > v;
  for (int i = 1; i <= n; i++) {
    cin >> b[i];
    for (int j = 1; j <= 6; j++) v.push_back({b[i] - a[j], i});
  }
  sort(v.begin(), v.end());
  map<int, deque<int> > m;
  for (int i = 0; i < (int)v.size(); i++) {
    while (lst < (int)v.size() && (int)m.size() < n) {
      m[v[lst].second].push_back(v[lst].first);
      lst++;
    }
    if ((int)m.size() == n) ans = min(ans, v[lst - 1].first - v[i].first);
    m[v[i].second].pop_front();
    if ((int)m[v[i].second].size() == 0) m.erase(v[i].second);
  }
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ;
  int T = 1;
  while (T--) {
    TestCase();
    cout << "\n";
  }
  return 0;
}
