#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,unroll-loops")
using namespace std;
const int N = 1e5 + 2;
long long a[N], b[N];
map<int, vector<long long> > frets;
vector<long long> vec;
map<int, int> notes;
void add(int pos) {
  vector<long long> &note = frets[vec[pos]];
  for (auto x : note) notes[x]++;
}
void rem(int pos) {
  vector<long long> &note = frets[vec[pos]];
  for (auto x : note) {
    notes[x]--;
    if (notes[x] == 0) notes.erase(x);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  for (int i = int(0); i < int(6); ++i) cin >> a[i];
  int n;
  cin >> n;
  for (int i = int(0); i < int(n); ++i) {
    cin >> b[i];
    for (int j = int(0); j < int(6); ++j) {
      long long fret = b[i] - a[j];
      if (fret <= 0) continue;
      frets[fret].push_back(i);
      vec.push_back(fret);
    }
  }
  sort(vec.begin(), vec.end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());
  if (int(vec.size()) == 1) {
    cout << 0 << endl;
    return 0;
  }
  int lo = 0, hi = 0;
  long long ans = 4e9;
  while (lo < int(vec.size())) {
    if (hi == int(vec.size()))
      rem(lo++);
    else if (lo == hi)
      add(hi++);
    else if (int(notes.size()) == n)
      rem(lo++);
    else
      add(hi++);
    if (int(notes.size()) == n) ans = min(ans, vec[hi - 1] - vec[lo]);
  }
  cout << ans << endl;
  return 0;
}
