#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
template <class T>
bool ckmin(T &a, T b) {
  return a > b ? a = b, true : false;
}
template <class T>
bool ckmax(T &a, T b) {
  return a < b ? a = b, true : false;
}
const int N = 2e5 + 500;
const int mod = 1e9 + 7;
const int INF = INT_MAX >> 1;
const ll LINF = LLONG_MAX >> 1;
const ld eps = 1e-9;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(20);
  vector<int> a(6);
  for (auto &e : a) cin >> e;
  int n;
  cin >> n;
  vector<int> b(n);
  for (auto &e : b) cin >> e;
  vector<int> lu(n, INF);
  vector<int> v;
  map<int, vector<int>> us;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 6; j++) {
      int x = b[i] - a[j];
      us[x].emplace_back(i);
      v.emplace_back(x);
    }
  }
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
  int cnt = 0, ans = INF;
  set<pair<int, int>> cur;
  for (int i = 0; i < n; i++) cur.insert(make_pair(INF, i));
  for (int i = 0; i < (int)v.size(); i++) {
    for (auto e : us[v[i]]) {
      if (lu[e] == INF) cnt++;
      cur.erase(cur.find(make_pair(lu[e], e)));
      lu[e] = v[i];
      cur.insert(make_pair(lu[e], e));
    }
    if (cnt == n) {
      ckmin(ans, v[i] - cur.begin()->first);
    }
  }
  cout << ans << endl;
  return 0;
}
