#include <bits/stdc++.h>
using namespace std;
struct segment {
  long long x, type, note;
  segment() = default;
  segment(int x, int type, int note) : x(x), type(type), note(note) {}
  bool operator<(const segment &s) const {
    return x < s.x || (x == s.x && type > s.type);
  }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  vector<long long> a(6);
  for (int i = 0; i < 6; i++) {
    cin >> a[i];
  }
  int n;
  cin >> n;
  vector<long long> b(n);
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }
  sort(b.begin(), b.end());
  b.resize(unique(b.begin(), b.end()) - b.begin());
  n = b.size();
  vector<int> cnt(n);
  long long l = -1, r = 2e9;
  vector<pair<long long, int>> s;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 6; j++) {
      s.emplace_back(b[i] - a[j], i);
    }
  }
  sort(s.begin(), s.end());
  while (r - l > 1) {
    long long m = (l + r) / 2;
    queue<pair<long long, int>> R;
    bool ok = false;
    int cntb = 0;
    for (auto [x, note] : s) {
      while (!R.empty() && R.front().first < x) {
        if (cntb == n) {
          ok = true;
        }
        cnt[R.front().second]--;
        if (cnt[R.front().second] == 0) {
          cntb--;
        }
        R.pop();
      }
      cnt[note]++;
      if (cnt[note] == 1) {
        cntb++;
      }
      R.emplace(x + m, note);
    }
    while (!R.empty()) {
      if (cntb == n) {
        ok = true;
      }
      cnt[R.front().second]--;
      if (cnt[R.front().second] == 0) {
        cntb--;
      }
      R.pop();
    }
    cnt.assign(n, 0);
    if (ok) {
      r = m;
    } else {
      l = m;
    }
  }
  cout << r << '\n';
  return 0;
}
