#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
const long long inf = 1e9 + 123, llinf = 1e18 + 829, ura = 684395049517,
                mod = 998244353;
void xru() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
void run() {
  cout << "\n";
  system("pause");
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
int main() {
  vector<long long> a(6);
  for (long long i = 0; i <= 6 - 1; i++) cin >> a[i];
  sort(a.begin(), a.end());
  long long n;
  cin >> n;
  vector<long long> b(n);
  for (long long i = 0; i <= n - 1; i++) cin >> b[i];
  vector<pair<long long, long long> > lad;
  for (long long i = 0; i <= n - 1; i++) {
    for (long long j = 0; j <= 5; j++) {
      lad.push_back({b[i] - a[j], i});
    }
  }
  sort(lad.begin(), lad.end());
  vector<long long> cnt(n, 0);
  set<long long> used;
  long long r = 0, ans = inf;
  for (long long l = 0; l <= (long long)(lad.size()) - 1; l++) {
    while (r < (long long)(lad.size()) && (long long)(used.size()) < n) {
      if (cnt[lad[r].second] == 0) used.insert(lad[r].second);
      cnt[lad[r].second]++;
      r++;
    }
    if ((long long)(used.size()) == n) {
      ans = min(ans, lad[r - 1].first - lad[l].first);
    }
    cnt[lad[l].second]--;
    if (cnt[lad[l].second] == 0) used.erase(lad[l].second);
  }
  cout << ans;
}
