#include <bits/stdc++.h>
using namespace std;
long long const INF = 1e9;
long long const MOD = 1e9 + 7;
void solve() {
  vector<long long> a(6);
  for (long long i = 0; i < 6; i++) {
    cin >> a[i];
  }
  long long n;
  cin >> n;
  vector<long long> b(n);
  for (long long i = 0; i < n; i++) {
    cin >> b[i];
  }
  vector<vector<long long>> L(n, vector<long long>(6));
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < 6; j++) {
      L[i][j] = b[i] - a[j];
    }
  }
  vector<pair<long long, long long>> p;
  long long mn = INF, nx = 0;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < 6; j++) {
      p.push_back({L[i][j], i});
    }
  }
  sort(p.begin(), p.end());
  long long N = n * 6;
  map<long long, long long> m;
  long long l = 0, r = -1, ans = INF, k = 0;
  for (; l < N; l++) {
    while (k < n && r < N) {
      r++;
      if (m[p[r].second] == 0ll) {
        k++;
      }
      m[p[r].second]++;
    }
    if (k == n) {
      ans = min(ans, abs(p[r].first - p[l].first));
    }
    m[p[l].second]--;
    if (m[p[l].second] == 0) {
      k--;
    }
    if (k == n) {
      ans = min(ans, abs(p[r].first - p[l].first));
    }
  }
  cout << ans;
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(7);
  long long t = 1;
  while (t--) {
    solve();
    cout << endl;
  }
  return 0;
}
