#include <bits/stdc++.h>
using namespace std;
template <typename T>
istream& operator>>(istream& in, vector<T>& a) {
  for (auto& i : a) in >> i;
  return in;
}
template <typename T>
ostream& operator<<(ostream& out, vector<T>& a) {
  for (auto& i : a) out << i << " ";
  return out;
}
template <typename T, typename U>
void chkmin(T& a, U b) {
  if (a > b) a = b;
}
template <typename T, typename U>
void chkmax(T& a, U b) {
  if (a < b) a = b;
}
constexpr int INF = 1e9 + 9;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  vector<int> a(6);
  cin >> a;
  int n;
  cin >> n;
  vector<int> b(n);
  cin >> b;
  sort((a).begin(), (a).end()), sort((b).begin(), (b).end());
  vector<deque<int>> points(n);
  multiset<int> open;
  vector<pair<int, int>> events;
  for (int i = (int)0; i < (int)n; i++) {
    for (int j = (int)0; j < (int)6; j++) {
      points[i].push_back(b[i] - a[j]);
      events.emplace_back(points[i].back(), i);
    }
    open.insert(points[i].back());
  }
  int ans = INF;
  sort((events).begin(), (events).end());
  for (auto [x, idx] : events) {
    if (open.size() < n) break;
    if (false) cerr << x << " " << *open.rbegin() << "\n";
    chkmin(ans, *open.rbegin() - x);
    open.erase(open.find(points[idx].back()));
    points[idx].pop_back();
    if (!points[idx].empty()) open.insert(points[idx].back());
  }
  cout << ans;
  return 0;
}
