#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const int maxn = 1e5 + 3;
int a[8];
int n;
int b[maxn];
void read() {
  for (int i = 1; i <= 6; i++) cin >> a[i];
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> b[i];
}
int idx[maxn];
void solve() {
  sort(a + 1, a + 6 + 1);
  vector<int> v;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= 6; j++) v.push_back(b[i] - a[j]);
  sort(v.begin(), v.end());
  set<pair<int, int> > s;
  for (int i = 1; i <= n; i++) {
    s.insert({b[i] - a[6], i});
    idx[i] = 6;
  }
  int ans = INT_MAX;
  for (auto i : v) {
    bool can = true;
    while (s.begin()->first < i) {
      auto curr = *s.begin();
      s.erase(s.begin());
      if (idx[curr.second] == 1) {
        can = false;
        break;
      }
      idx[curr.second]--;
      s.insert({b[curr.second] - a[idx[curr.second]], curr.second});
    }
    if (!can) break;
    ans = min(ans, prev(s.end())->first - i);
  }
  cout << ans << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  read();
  solve();
}
