#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<int> a(6);
  for (int i = 0; i < 6; i++) cin >> a[i];
  int n;
  cin >> n;
  vector<int> b(n);
  for (int i = 0; i < n; i++) cin >> b[i];
  vector<pair<int, int>> bag;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < 6; j++) bag.push_back({b[i] - a[j], i});
  sort(bag.begin(), bag.end());
  int m = bag.size();
  vector<int> r(m, m);
  int p = -1;
  int cnt = 0;
  vector<int> has(n);
  for (int i = 0; i < m; i++) {
    while (cnt < n && p < m) {
      p++;
      if (!has[bag[p].second]) {
        cnt++;
      }
      has[bag[p].second]++;
    }
    if (p == m) break;
    r[i] = p;
    if (--has[bag[i].second] == 0) cnt--;
  }
  int res = 2E9;
  for (int i = 0; i < m; i++) {
    if (r[i] == m) break;
    res = min(res, bag[r[i]].first - bag[i].first);
  }
  cout << res << '\n';
}
