#include <bits/stdc++.h>
using namespace std;
const long long inf = 2e9;
const long long maxn = 2e5 + 1;
const bool debug = 0;
const int64_t INF = 1e17;
const long long module = 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);
  vector<pair<long long, long long> > line;
  for (long long i = 0; (i) < n; ++(i)) {
    cin >> b[i];
  }
  for (long long i = 0; (i) < n; ++(i)) {
    for (long long j = 0; (j) < 6; ++(j)) {
      long long x = b[i] - a[j];
      line.push_back(make_pair(x, i));
    }
  }
  sort(line.begin(), line.end());
  long long l = 0, k = 0, answer = inf;
  vector<long long> d(((long long)(line).size()), 0);
  for (long long r = 0; (r) < ((long long)(line).size()); ++(r)) {
    if (d[line[r].second] == 0) k++;
    d[line[r].second]++;
    while (d[line[l].second] > 1) {
      d[line[l].second]--;
      l++;
    }
    if (k == n) answer = min(answer, (line[r].first - line[l].first));
  }
  cout << answer;
}
int32_t main() {
  if (!debug) {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(0);
  }
  long long tests = 1;
  for (long long _ = 0; (_) < tests; ++(_)) {
    solve();
    cout << "\n";
  }
  return 0;
}
