#include <bits/stdc++.h>
using namespace std;
template <class T>
ostream& operator<<(ostream& out, vector<T>& v) {
  out << "[";
  for (auto k : v) out << k << " ";
  out << "]"
      << "\n";
  return out;
}
template <class T>
ostream& operator<<(ostream& out, set<T> s) {
  out << "{";
  for (auto k : s) out << k << " ";
  out << "}"
      << "\n";
  return out;
}
template <class T, class U>
ostream& operator<<(ostream& out, pair<T, U> p) {
  out << "[ " << p.first << " , " << p.second << " ] ";
  return out;
}
template <class T, class U>
istream& operator>>(istream& in, pair<T, U>& p) {
  in >> p.first >> p.second;
  return in;
}
int a[6], app[200000], cant = 0;
vector<pair<int, int> > vec;
int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);
  int mindif = 2e9;
  for (int i = 0; i < int(6); i++) cin >> a[i];
  int n;
  cin >> n;
  for (int i = 0; i < int(n); i++) {
    int b;
    cin >> b;
    for (int j = 0; j < int(6); j++) {
      if (a[j] <= b) {
        vec.push_back({b - a[j], i});
      }
    }
  }
  sort(vec.begin(), vec.end());
  int i = -1, j = 0;
  while (i < int(vec.size())) {
    if (cant < n) {
      i++;
      if (i == vec.size()) break;
      app[vec[i].second]++;
      if (app[vec[i].second] == 1) cant++;
    } else {
      mindif = min(mindif, vec[i].first - vec[j].first);
      if (app[vec[j].second] == 1) cant--;
      app[vec[j].second]--;
      j++;
    }
  }
  cout << mindif << "\n";
  return 0;
}
