#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fll;
const int MAX = 1e5 + 2;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  vector<int> second(6);
  for (int i = 0; i < 6; i++) cin >> second[i];
  int n;
  cin >> n;
  vector<int> b(n);
  for (int i = 0; i < n; i++) cin >> b[i];
  vector<pair<int, int> > p(6 * n);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 6; j++) {
      p[i * 6 + j] = {b[i] - second[j], i};
    }
  }
  sort(p.begin(), p.end());
  int l = 0, r = -1;
  vector<int> h(n);
  int ans = INF;
  set<int> c;
  while (r < 6 * n - 1) {
    if (c.size() < n) {
      r++;
      c.insert(p[r].second);
      h[p[r].second]++;
    }
    if (c.size() >= n) {
      ans = min(ans, p[r].first - p[l].first);
      h[p[l].second]--;
      if (h[p[l].second] == 0) c.erase(p[l].second);
      l++;
    }
  }
  cout << ans << '\n';
  exit(0);
}
