#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e9;
void fast() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
signed main() {
  fast();
  vector<long long> a(6);
  for (long long& e : a) cin >> e;
  long long n;
  cin >> n;
  vector<long long> b(n);
  vector<pair<long long, long long> > points;
  long long j = 0;
  for (long long& e : b) {
    cin >> e;
    for (long long& e1 : a) {
      if (e > e1) points.push_back({e - e1, j});
    }
    ++j;
  }
  sort((points).begin(), (points).end());
  vector<long long> cnt(n + 1);
  long long dif = 0;
  long long l = 0, r = 0, ans = 3 * INF;
  while (l < points.size()) {
    if (dif < n && (l == r || r < points.size())) {
      long long cord = points[r].first;
      long long ind = points[r].second;
      if (cnt[ind] == 0) {
        ++dif;
      }
      ++cnt[ind];
      ++r;
    } else {
      if (dif == n) {
        ans = min(points[r - 1].first - points[l].first, ans);
      }
      long long ind = points[l].second;
      if (cnt[ind] == 1) {
        --dif;
      }
      --cnt[ind];
      ++l;
    }
  }
  cout << ans << '\n';
  return 0;
}
