#include <bits/stdc++.h>
using namespace std;
const int C = 6;
const int N = 1e5;
int n;
int a[C], b[N];
int l[C], r[C];
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  for (int i = 0; i < C; ++i) {
    cin >> a[i];
  }
  sort(a, a + C);
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> b[i];
  }
  sort(b, b + n);
  int ans = b[n - 1] - b[0];
  for (int j = 0; j < C; ++j) {
    for (int i = 0; i < n; ++i) {
      for (int k = 0; k < C; ++k) {
        r[k] = upper_bound(b, b + n, b[i] - a[j] + a[k]) - b - 1;
      }
      if (*max_element(r, r + C) < n - 1) {
        continue;
      }
      l[0] = 0;
      for (int k = 1; k < C; ++k) {
        l[k] = r[k - 1] + 1;
      }
      vector<int> arr;
      for (int k = 0; k < C; ++k) {
        if (l[k] <= r[k]) {
          if (l[k] >= 0 && l[k] < n) {
            arr.push_back(b[l[k]] - a[k]);
          }
          if (r[k] >= 0 && r[k] < n) {
            arr.push_back(b[r[k]] - a[k]);
          }
        }
      }
      sort(arr.begin(), arr.end());
      ans = min(ans, arr.back() - arr[0]);
    }
  }
  cout << ans << '\n';
  return 0;
}
