#include <bits/stdc++.h>
const long long INF = 1e15;
const long long mod = 1e9 + 7;
using namespace std;
vector<long long> a(6);
vector<long long> b;
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  srand(time(NULL));
  for (long long i = 0; i < 6; i++) {
    cin >> a[i];
  }
  long long n;
  cin >> n;
  b.resize(n);
  for (long long i = 0; i < n; i++) {
    cin >> b[i];
  }
  vector<pair<long long, long long>> c;
  for (long long i = 0; i < 6; i++) {
    for (long long j = 0; j < n; j++) {
      c.push_back({b[j] - a[i], j});
    }
  }
  sort(c.begin(), c.end());
  long long l = 0, r = 0;
  long long cnt = 0;
  vector<long long> p(n, 0);
  long long ans = 1e10;
  while (l < c.size()) {
    while (r < c.size() && cnt < n) {
      long long x = c[r].second;
      if (!p[x]) cnt++;
      p[x]++;
      r++;
    }
    if (cnt == n) ans = min(ans, c[r - 1].first - c[l].first);
    long long x = c[l].second;
    if (p[x] == 1) cnt--;
    p[x]--;
    l++;
  }
  cout << ans;
  return 0;
}
