#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  srand(time(NULL));
  ;
  long long t, k, n, m, d, u, v;
  t = 1;
  while (t--) {
    vector<long long> a(6);
    for (int i = 0; i < 6; i++) cin >> a[i];
    cin >> n;
    vector<long long> b(n);
    for (int i = 0; i < n; i++) {
      cin >> b[i];
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    long long ans = LONG_LONG_MAX;
    for (int i = 0; i < 6; i++) {
      for (int j = 0; j < n; j++) {
        m = b[j] - a[i];
        if (b[0] - a[0] >= m) {
          long long diff = 0;
          for (int k = 0; k < 6; k++) {
            long long last = n;
            if (k + 1 < 6)
              last = lower_bound(b.begin(), b.end(), m + a[k + 1]) - b.begin();
            if (last > 0) diff = max(diff, b[last - 1] - a[k]);
          }
          ans = min(ans, diff - m);
        }
      }
    }
    cout << ans << "\n";
  }
  return 0;
}
