#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 1;
const long long INFLL = 1e18 + 1;
int main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
  vector<int> a(6);
  for (auto &c : a) cin >> c;
  int n;
  cin >> n;
  vector<int> b(n);
  for (auto &c : b) cin >> c;
  vector<pair<int, int>> l;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 6; j++) {
      l.emplace_back(b[i] - a[j], i);
    }
  }
  sort((l).begin(), (l).end());
  vector<vector<int>> gist(n);
  int mx = -1;
  for (int i = 0; i < (int)l.size(); i++) {
    gist[l[i].second].emplace_back(i);
    if ((int)gist[l[i].second].size() == 1) mx = max(mx, l[i].first);
  }
  vector<int> p(n, 0);
  int ans = INF;
  for (int i = 0; i < (int)l.size(); i++) {
    ans = min(ans, mx - l[i].first);
    if (p[l[i].second] == 5) break;
    p[l[i].second]++;
    mx = max(mx, l[gist[l[i].second][p[l[i].second]]].first);
  }
  cout << ans;
  return 0;
}
