#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 1e5 + 2;
const int inf = 2e9;
const long long linf = 4e18;
int a[6], b[maxn], c[maxn];
void solve() {
  for (int i = 0; i < 6; i++) cin >> a[i];
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> b[i];
  vector<pair<int, int> > d;
  for (int i = 0; i < 6; i++) {
    for (int j = 0; j < n; j++) {
      d.push_back({abs(a[i] - b[j]), j});
    }
  }
  sort(d.begin(), d.end());
  memset(c, -1, sizeof(c));
  int ans = inf;
  set<pair<int, int> > s;
  for (int i = 0; i < 6 * n; i++) {
    int val = d[i].first, idx = d[i].second;
    s.erase({c[idx], idx});
    c[idx] = val;
    s.insert({val, idx});
    if (s.size() == n) {
      ans = min(ans, (s.rbegin()->first) - (s.begin()->first));
    }
  }
  cout << ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cerr.tie(0);
  int tt = 1;
  while (tt--) solve();
  return 0;
}
