#include <bits/stdc++.h>
using namespace std;
const long long oo = int(1e9);
inline void yn(int x) {
  if (!x)
    cout << "NO\n";
  else if (x)
    cout << "YES\n";
  return;
}
const long long N = 3e5 + 5, M = 1e9 + 7, mod = 998244353;
void solve() {
  vector<long long> a(6);
  for (long long i = 0; i < 6; i++) cin >> a[i];
  ;
  long long n;
  cin >> n;
  vector<long long> b(n);
  for (long long i = 0; i < n; i++) cin >> b[i];
  ;
  vector<pair<long long, long long> > v;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < 6; j++) {
      v.push_back({b[i] - a[j], i});
    }
  sort((v).begin(), (v).end());
  long long N = 0, l = 0, r = 0, ans = oo;
  vector<long long> notes(n, 0);
  while (r < 6 * n) {
    while (r < 6 * n && N != n) {
      notes[v[r].second]++;
      if (notes[v[r].second] == 1) N++;
      r++;
    }
    while (l < r && N == n) {
      notes[v[l].second]--;
      if (notes[v[l].second] == 0) N--;
      l++;
    }
    ans = min(ans, v[r - 1].first - v[l - 1].first);
  }
  cout << (ans) << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);
  int tc = 1;
  while (tc--) {
    solve();
  }
  return 0;
}
