#include <bits/stdc++.h>
using namespace std;
struct Data {
  int val;
  int i, j;
};
bool operator<(Data a, Data b) { return a.val < b.val; }
const int INF = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  vector<int> a(6);
  for (int i = 0; i < 6; ++i) {
    cin >> a[i];
  }
  int n;
  cin >> n;
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  vector<vector<int>> b(n, vector<int>(6, 0));
  vector<Data> data;
  for (int i = 0; i < n; ++i) {
    int first;
    cin >> first;
    for (int j = 0; j < 6; ++j) {
      b[i][j] = first - a[j];
      data.push_back({b[i][j], i, j});
    }
  }
  sort(data.begin(), data.end());
  vector<int> its(n, 0);
  multiset<int> q;
  for (int i = 0; i < n; ++i) {
    q.insert(b[i][0]);
  }
  int res = INF;
  for (auto first : data) {
    int second = *q.rbegin() - first.val;
    res = min(res, second);
    int i = first.i;
    q.erase(q.find(b[i][its[i]]));
    ++its[i];
    if (its[i] == 6) break;
    q.insert(b[i][its[i]]);
  }
  cout << res << "\n";
}
